开发者

Assigning same NSString multiple times

Can an NSString be reused l开发者_如何学Cike this:

NSString *string = @"first value";

NSLog(string);

string = @"second value";

NSLog(string);

This works when tested, but is it proper coding?

Thanks.


Yes, your example is totally fine. What is your concern about it being 'improper'?

Edit: Strictly speaking it is probably safer to use:

NSLog(@"%@", string);

Instead of just logging the string directly. I don't think that's what you were asking, though.


You are not changing the string. Instead you are just assigning a different address to the pointer string.

and @"first String" and @"second String" are just constant strings.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜