Find indexOfObject from NSArray

I have an NSArray populated with custom objects. Each object has several variables: pk, quantity, date, etc.

I want to get the object that has the largest number in the variable pk. 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 this object. I saw indexOfObject when an array has only 1 data variable, but how can I use it in this instance?

thanks

+4
source share
1 answer

Use -indexOfObjectPassingTest: for example:

 NSUInteger idx = [bets indexOfObjectPassingTest:^(id obj, NSUInteger idx, BOOL *stop) { return [obj pk] == maximumpk; }]; 
+11
source

Source: https://habr.com/ru/post/1385641/


All Articles