Just doing some research on searching for a character or word within a NSString and I came across this code snippet (which works like a charm):
return [sourceString rangeOfString:searchString].location != NSNotFound;
Am I right in thinking that the above code is functionally identical to:
NSRange range = [sourceString rangeOfString:searchString];
if (range.location == NSNotFound)
return NSNotFound;
else
return range.location;
Obviously the first snippet is much cleaner but I’m not clear on the != NSNotFound part. Could someone explain that to me?
The
!=operator evaluates to a boolean, so it’s equivalent to:Which is the same as: