You need to write your own check, but it is quite simple:
NSString *str = ...
NSRange range = ...
if (range.location != NSNotFound && range.location + range.length <= str.length) {
}
You can create a category method in NSStringthat will add your proposed method rangeExists:. It will be simple:
- (BOOL)rangeExists:(NSRange)range {
return range.location != NSNotFound && range.location + range.length <= self.length;
}
source
share