212NSString and NSMutableString

Should have been clear, but was not:

NSString *s = @"aString";
s = @"anotherString";
NSLog(@"%@", s);
// anotherString
 
NSMutableString *m = @"aMutableString";
[m appendString:@"andAnAppendedString"];
NSLog(@"%@", m);
// aMutableStringandAnAppendedString

NString allows for the replacement of its whole content by simply assigning a new value.

With NSMutableString it is possible to add/delete/insert strings at arbitrary places in a string.

201Changing NSMutableString into NSString

NSMutableString *s;

-(void)functionA:(NSString *)string {
[self.s appendString: string];
}

-(void)functionB:(NSString *)string {
NSString* c = self.s;
NSString* c = [NSString stringWithString: self.s];
}

“Returns a string created by copying the characters from another given string.”

self.s is a refernce to s, might change over time, stringWithString makes a copy, a “snapshot” of self.s…