Jakub Gawecki
Jakub Gawecki

Reputation: 1229

Objective-C Declaring NSMutableString

I was wondering why can we declare NSString like this:

NSString *strongName            = @"Kuba";

But we cannot declare NSMutableString the same way:

NSMutableString *strongName2    = @"Kuba";

Instead, I have to use older(?) approach:

NSMutableString *strongName3 = [NSMutableString stringWithFormat:@"Kuba"];

Thank you for any meaningful insight :))

Upvotes: 1

Views: 58

Answers (1)

Alejandro Iván
Alejandro Iván

Reputation: 4051

NSString *myString = @"Kuba" is a shorthand for NSString alone. If you need a NSMutableString, you could get a mutable copy from it: NSMutableString *myMutableString = [@"Kuba" mutableCopy].

Upvotes: 2

Related Questions