Add a category to NSString using the method:
-(id)objectAtIndexedSubscript:(NSUInteger)idx { if(idx >= self.length) { return nil; } return @([self characterAtIndex:idx]); }
and name it as follows:
unichar c = [foo[i] unsignedShortValue]
Note that c will be 0 when the character is a null character, or the index is outside.
source share