I have a Car class. It’s got a property called enginePower. On the other hand I have an NSArray that contains more than 50 car objects. How would I select the car with the highest enginePower which at the same time is less than the given value. To be more clear:
BMW X5-345 hp
Audi A3-200 hp
BMW 525i -225 hp
VW Passat CC-175 hp
.....
Now, from this array of cars when I ask for the car with the highest enginePower which is less than 320 it should give me BMW 525i. Is it possible to achieve. I mean is there a nice and easy way or does it need lots of lines of code?
The answer provided by @Jasarien would work just fine, but if you want to avoid writing the code to loop through you might try something like: