NSString and NSMutableString


Perhaps even NSArray and NSMutableArray

I am going to take it that one is immutable and the other is not. however, why is

NSString *string = @"Jesus";

Good and

NSMutableString *string = @"Jesus"; 

generates a warning?


This link isn’t precisely an answer to your question, but it covers some of the essentials: stackoverflow.com/questions/2574 … ng-literal

In short, @"" is a string literal that cannot be modified. You need to use initWithString: or comparable instead of a direct assignment.


Thank you for your reply.

I have one more question. Appending a string onto another to form a continuously growing new string.

I understand a bit more about Mutable and Immutable strings but I am having trouble doing what I want.

	NSString *one = [[NSString alloc]initWithString:@"1"];
	NSString *displayedValue = [textField stringValue];
	display = [NSMutableString stringWithString:[displayedValue stringByAppendingString:one]];
	NSLog(@"%@", display);

Perhaps my understanding is not as good as I thought. I appreciate your assistance.