Reputation: 663
What is the correct if statement to check if a NSNumber is between two values? For example between 33 and 66?
if ([myNumber intValue] < 33) {
}
Upvotes: 0
Views: 380
Reputation: 22641
Objective C is an extension of C, so you can combine two comparisons with &&
:
if ([myNumber intValue] > 33 && [myNumber intValue] < 66) {
Or modern style:
if (myNumber.intValue > 33 && myNumber.intValue < 66) {
Upvotes: 3