0
votes

i have an NSMutableArray that contains some NsDictionary with NSstring for differents Keys. Somethings like:

NSDictionary *ExempleDictionary = [NSDictionary dictionaryWithObjectsAndKeys:[Date objectAtIndex:sender.tag],@"DATE",[Time objectAtIndex:sender.tag],@"TIME", nil];

I'd like to check if a particular object with DATE=xxx && TIME=xxx exist in the Array.

Any idea?!

2
You have an array where each element is a dictionary? Or you have a dictionary where each value is an array? - Oren
There are various predicate and key/value coding approaches (depending on your specific needs, which is unclear), but these are rarely much faster than simply coding the obvious loops and tests. So if you can't figure out the "fancy" way, try just coding up a loop to do the search. - Hot Licks

2 Answers

1
votes

You can do the search with NSPredicate:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF.DATE=%@ AND SELF.TIME=%@", dateVal, timeVal];
NSArray *filteredArray = [myArray filteredArrayUsingPredicate:predicate];

filteredArray contains an NSArray of all NSDictionary objects matching the specified date and time condition. You can retrieve the matching objects by iterating the filtered array.

0
votes

You can use NSArray's containsObject: (if you have a reference to the dictionary laying around) or indexOfObjectIdenticalTo: (if you want to check if an element identical to the one you are passing -but not necessarily the same object- is in the array). Both are explained in the docs:

containsObject

indexOfObjectIdenticalTo