I have an NSArray filled with custom objects. Each object has several variables: pk, amount, date etc..
I want to fetch the object that has the highest number in the pk variable. I can do this using:
NSUInteger maximumpk = [[bets valueForKeyPath:@"@max.pk"] intValue];
This gives me the actual value from the highest pk. Now I need to get the index for that object. I have seen indexOfObject used when the array has just 1 variable of data, but how do I use it in this instance?
Thanks
Use -indexOfObjectPassingTest:
, for example:
NSUInteger idx = [bets indexOfObjectPassingTest:^(id obj, NSUInteger idx, BOOL *stop) {
return [obj pk] == maximumpk;
}];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With