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.
精彩评论