Thursday, May 9, 2013

NSDictionary isEqualToDictionary example ios


isEqualToDictionary:

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
otherDictionary
The dictionary with which to compare the receiving dictionary.
Return Value of [NSDictionary isEqualToDictionary]
YES if the contents of otherDictionary are equal to the contents of the receiving dictionary, otherwise NO.
Discussion of [NSDictionary isEqualToDictionary]
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 isEqualToDictionary]
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 isEqualToDictionary]
- (BOOL) dictionaryArray:(NSMutableArray*)array containsDictionary:(NSDictionary*)givenDictionary
{
    BOOL result = NO;

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

    return result;
}