Guest User

Untitled

a guest
Feb 19th, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. NSDictionary *someDict = [NSDictionary dictionaryWithObjectsAndKeys: @"Foo", @"Bar", @"Fizz", @"buzz", nil];
  2. SomeObj *anObject = [[SomeObj alloc] init];
  3. [anObject setDictionaryRepresentation:someDict];
  4.  
  5. NSDictionary *someOtherDict = [NSDictionary dictionaryWithObjectsAndKeys: @"Food", @"Biz", @"Bazzz", @"Fizzle", nil];
  6. SomeObj *anotherObject = [[SomeObj alloc] init];
  7. [anotherObject setDictionaryRepresentation:someOtherDict];
  8.  
  9. NSDictionary *someDictionarySameAsSomeDict = [NSDictionary dictionaryWithObjectsAndKeys: @"Fizz", @"buzz", @"Foo", @"Bar", nil];
  10. SomeObj *someThirdObject = [[SomeObj alloc] init];
  11. [someThirdObject setDictionaryRepresentation:someDictionarySameAsSomeDict];
  12.  
  13.  
  14. NSPredicate *isEqualTemplate = [NSPredicate predicateWithFormat:@"dictionaryRepresentation = $SOME_DICTIONARY"];
  15. NSPredicate *filter = [isEqualTemplate predicateWithSubstitutionVariables:[NSDictionary dictionaryWithObject:someDict forKey:@"SOME_DICTIONARY"]];
  16.  
  17. NSArray *easyOne = [NSArray arrayWithObjects: anObject, anotherObject, nil];
  18. NSArray *someFilteredObjects = [easyOne filteredArrayUsingPredicate:filter];
  19. NSLog(@"%@ ", someFilteredObjects);
  20. assert([someFilteredObjects objectAtIndex:0] == anObject);
  21.  
  22. NSArray *harderOne = [NSArray arrayWithObjects: someThirdObject, anotherObject, nil];
  23. someFilteredObjects = [harderOne filteredArrayUsingPredicate:filter];
  24. NSLog(@"%@ ", someFilteredObjects);
  25. assert([someFilteredObjects objectAtIndex:0] == someThirdObject);
  26.  
  27.  
  28. NSArray *hardestOne = [NSArray arrayWithObjects: anObject, someThirdObject, anotherObject, nil];
  29. someFilteredObjects = [hardestOne filteredArrayUsingPredicate:filter];
  30. NSLog(@"%@ ", someFilteredObjects);
  31. assert([someFilteredObjects containsObject:someThirdObject]);
  32. assert([someFilteredObjects containsObject:anObject]);
Add Comment
Please, Sign In to add comment