Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does NSMakeRange(i, 1) mean?

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?

like image 232
Xiaodong Gong Avatar asked Jan 19 '13 09:01

Xiaodong Gong


2 Answers

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.

like image 188
bdash Avatar answered Oct 28 '22 02:10

bdash


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.

like image 36
zoul Avatar answered Oct 28 '22 01:10

zoul