Created
July 14, 2015 05:09
-
-
Save ranmyfriend/d73da76d4911913768b2 to your computer and use it in GitHub Desktop.
We can't simply cross check the index value with nil! <NSNotFound>
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NSArray *array = @[@(1),@(2),@(3)]; | |
NSInteger index = [array indexOfObject:@(4)]; | |
/** @abstract: we can’t compare the index and also we can’t able to check whether it is a nil value or not? | |
Coz, its a Long Long integer. if you print the index on debugger window, you will get this value: 9223372036854775807 | |
Thats why we are checking with NSNotFound | |
If you don't don the defence check you will crash. Its safety check!. | |
*/ | |
if(index == NSNotFound) { | |
// index value is not found ! | |
// Use the NSAssert for handling the value or !value here. | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment