Why don't this line has an asterisk sign?


#1
NSString listOfNames = @"..."; // a long list of names
NSString name = @"Ward";
NSRange match = [listOfNames rangeOfString:name];
if (match.location == NSNotFound) {
    NSLog(@"No match found!");
    // Other actions to be taken
} else {
    NSLog(@"Match found!");
    // Other actions to be taken
}

why didn’t we add asterisk sign on the code in line 1,2 and 3.
like this

NSString *listOfNames

#2

These are wrong:

NSString listOfNames = @"..."; // a long list of names
NSString name = @"Ward";

They need the asterisk:

NSString * listOfNames = @"..."; // a long list of names
NSString * name = @"Ward";

This is correct:

NSRange match = [listOfNames rangeOfString:name];

Can’t use asterisk in this context because rangeOfString: returns an NSRange instance by value not by reference.


#3

ibex10 nailed it, but it’s also worth pointing out that NSString is the name of a class, whose instances live on the heap, meaning that we must use pointers any time we’re dealing with them. NSRange is the name of a struct, whose instances live on the stack, and as such, we don’t tend to use pointers to them.