My code won’t work and I don’t know why
the following works:
NSString * words (void) {
return [NSString stringWithFormat:@"You sent %d words\n", 1];
}
but this won’t work:
NSString * words (void) {
return [[[NSString alloc] stringWithFormat:@"You have %d words\n", 1] autorelease];
}
What’s wrong, when I’m releasing it, then it wont work. Help me please.
Change
stringWithFormat:toinitWithFormat:.stringWithFormat:is a class method so it is called when theNSStringclass itself is the receiver.initWithString:is an instance method so it is called when you have anNSStringinstance as the receiver, like what is returned from[NSString alloc].