I can't quite get my head around the difference between these two concepts (I'm coming to Cocoa from REALbasic).
Apparently, you can't alter the value of an immutable string after it has been created. This excerpt is taken from this pdf book:
How come the program prints MacBook Pro? If you can't change an immutable string then surely it would print what was initially assigned to it (i.e. iBook).
Sorry for such a dumb question!
MadDoc,
Apparently, you can't alter the value of an immutable string after it has been created. This excerpt is taken from this pdf book:
Code:
Once you have initialized the variable, i.e. favoriteComputer, you may give the variable another value, but you can-
not change the string itself [5.7] because it is an instance of class NSString. More on this in a minute.
#import <foundation/foundation.h>
int main (int argc, const char *argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSString *favoriteComputer;
favoriteComputer = @"iBook"; // [5.7]
favoriteComputer = @"MacBook Pro";
NSLog(@"%@", favoriteComputer);
[pool release];
return 0;
}
When executed, the program prints:
MacBook Pro
How come the program prints MacBook Pro? If you can't change an immutable string then surely it would print what was initially assigned to it (i.e. iBook).
Sorry for such a dumb question!
MadDoc,