NSString and NSMutableString?

Hello,

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?

thanks
jackyjoy

1 Like

This is because the @"Hello" syntax always makes an instance of NSString, regardless of the type of pointer you declare on the left hand side of the = operator.

So those two samples are equivalent to:
NSString *string = [NSString new];
and
NSMutableString *string = [NSString new];

That is, the actual object you are creating is an immutable string object in both cases, and the compiler is warning you that you have declared a reference to a mutable string object, but then made it refer to an immutable string object.

Does that help?

1 Like

thanks my issue has been fixed.