Franck
Franck

Reputation: 9329

NSString format question

Here are two ways to make a NSString.

NSString *sBody = [NSString stringWithString:@"Hello"]

versus

NSString *sBody = @"Hello"

Most of the time, I see it the first way. But is it also "clean" to use the second, or is it better to not use it?

Thanks and have a nice day!

Upvotes: 2

Views: 169

Answers (2)

Ricardo Augusto
Ricardo Augusto

Reputation: 558

It's the same, the first way you're helping the compiler but it already does a great job optimizing string vars.

Upvotes: 2

Ryan
Ryan

Reputation: 16636

They are equivalent. It's less code to use the literal (the second example), so I would just use that.

Upvotes: 4

Related Questions