I am trying to return the index of a word in a string but can't figure out a way to handle case where it is not found. Following does not work because nil does not work. Have tried every combination of int, NSInteger, NSUInteger etc. but can't find one compatible with nil. Is there anyway to do this? Thanks for
-(NSUInteger) findIndexOfWord: (NSString*) word inString: (NSString*) string {
NSArray *substrings = [string componentsSeparatedByString:@" "];
if([substrings containsObject:word]) {
int index = [substrings indexOfObject: word];
return index;
} else {
NSLog(@"not found");
return nil;
}
}