Skip to content

Instantly share code, notes, and snippets.

@icodebuster
Created February 18, 2014 04:51
Show Gist options
  • Save icodebuster/9064806 to your computer and use it in GitHub Desktop.
Save icodebuster/9064806 to your computer and use it in GitHub Desktop.
Using predicate to retrieve an index of an object in an NSArray.
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"self.id == %@", @"1"];
NSUInteger index = [mainArray indexOfObjectPassingTest:^(id obj, NSUInteger idx, BOOL *stop) {
return [predicate evaluateWithObject:obj];
}];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment