Skip to content

Instantly share code, notes, and snippets.

@ranmyfriend
Created July 14, 2015 05:09
Show Gist options
  • Save ranmyfriend/d73da76d4911913768b2 to your computer and use it in GitHub Desktop.
Save ranmyfriend/d73da76d4911913768b2 to your computer and use it in GitHub Desktop.
We can't simply cross check the index value with nil! <NSNotFound>
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