Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objective-C checks if array with ints contains int [closed]

Folks, I'm trying to do the following. I've got a array (NSArray) called 'specialLevels', that array looks like this:

specialLevels = @[@2, @4, @6, @9];

This should be a array of int's. I also got the int 'currentLevel' (basic int no object).

And I want to check if the currentLevel is in de array of specialLevels. I know the method 'containsObject' exists, but this won't work in my case.

What would you guys recommend to do in this case?

So I thought this, but it feels kinda strange imo:

if ([specialLevels containsObject:[NSNumber numberWithInt:currentLevel]]) {
 // other code in here
}
like image 404
ronnyrr Avatar asked Oct 09 '13 19:10

ronnyrr


1 Answers

You could alternatively write:

if ([specialLevels containsObject:@(currentLevel)]) {
    // other code in here
}

which is more in keeping with the style of your other code.

like image 79
Wain Avatar answered Oct 03 '22 19:10

Wain