Thursday, May 9, 2013

NSDictionary compare example ios

isEqualToDictionary:  (NSDictionary compare)

Returns a Boolean value that indicates whether the contents of the receiving dictionary are equal to the contents of another given dictionary.
- (BOOL)isEqualToDictionary:(NSDictionary *)otherDictionary
Parameters (NSDictionary compare)
The dictionary with which to compare the receiving dictionary.
Return Value  (NSDictionary compare)
YES if the contents of otherDictionary are equal to the contents of the receiving dictionary, otherwise NO.
Discussion  (NSDictionary compare)
Two dictionaries have equal contents if they each hold the same number of entries and, for a given key, the corresponding value objects in each dictionary satisfy the isEqual: test.
Example of (NSDictionary compare)
NSMutableDictionary *dictois = [[NSMutableDictionary new]autorelease];

[dictois setObject:@"easySpritedd" forKey:@"Nombre"];
[dictois setObject:@"X" forKey:@"290"];
[dictois setObject:@"Y" forKey:@"300"];

int fooIndex = [self.bloquesArray indexOfObjectPassingTest: ^(id obj, NSUInteger idx, BOOL *stop){
  if( [[obj class] isKindOfClass: [NSDictionary class]] ) {
    BOOL result = [obj isEqualToDictionary: diction];
    *stop = result;
    return result;

  *stop = NO;
  return NO;

Example of (NSDictionary compare)
- (BOOL) dictionaryArray:(NSMutableArray*)array containsDictionary:(NSDictionary*)givenDictionary
    BOOL result = NO;

    for( NSDictionary* dict in array )
        if( [dict isEqualToDictionary:givenDictionary] )
            result = YES;

    return result;