I just start to learn iOS.
What does "NSMakeRange(i, 1)
" mean?
for (int i = 0; i < [name length]; i++)
{
NSRange range = NSMakeRange(i, 1);
NSString *subString = [name substringWithRange:range];
const char *cString = [subString UTF8String];
if (strlen(cString) != 3)
{
return NO;
}
}
Where is it used?
NSMakeRange(i, 1)
creates a range with location i
and length 1
. See the documentation for NSMakeRange and NSString substringWithRange for further information and related functions.
Alt-click the function name in Xcode, you’ll get a reference. The function creates a range that starts at i
and has length of 1. In essence, you’re picking individual characters from the string.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With