I've seen a few examples around using NSArray indexOfObjectPassingTest, but I could not make them work (they would not return a valid index). So now I'm trying using an inline block. I have done it by typedef'ing a block, then setting it as a property, synthesizing it, and initializing it in the constructor. However that sort of renders the whole point mute, as I could easily create a method and use it instead (less typing, less effort).
What I'm trying to achieve is something along this:
Observations *obs = [self.myAppointment.OBSERVATIONS objectAtIndex: ^NSInteger (NSString *keyword){
for (Observations *obs in self.myAppointment.OBSERVATIONS) {
if ([obs.TIME isEqualToString:keyword] == YES) return (NSInteger)[self.myAppointment.OBSERVATIONS indexOfObject:obs];
}
return (NSInteger)-1;
}];
However Xcode simply won't have it. I've tried different variations, but declaring it inline seems to be a problem, which is weird, because as I've said, typedefing it, declaring, and synthesizing it works like this:
Observations *obs = [self.myAppointment.OBSERVATIONS objectAtIndex:findObs(keyword)];
Where findObs is again a defined block that does the same thing. Is this a syntax issue, or am I missing something else more important ?