I have a NSMutableArray pages with several objects (instances of Page). Each Page instance has a UUID and other properties, such as contents. When a page changes, everything may change except the UUID. After a change, I would like to find out the index of a particular Page in pages by using indexOfObject:. I use the UUID to identify the index I'm looking for and this works just fine:
NSMutableArray *uuids = [[NSMutableArray alloc] init];
for (int i = 0; i < [self.pages count]; i++) {
[uuids addObject:[[pages objectAtIndex:i] uuid]];
}
NSUInteger indexOfPage = [uuids indexOfObject:page.uuid];
Now my question is if there is a more elegant way to do this. All I really need is the index of the Page object in pages that has a given UUID.
There is
- (NSIndexSet *)indexesOfObjectsPassingTest:(BOOL (^)(id obj, NSUInteger idx, BOOL *stop))predicate or indexOfAccessibilityElement:<#(id)#> but I'm not really sure how either of these could help me out with my problem.