简体   繁体   中英

What does @“some string” mean in objective-c?

I'm just starting out with iphone development and ran across some example code that used @"somestring"

someLabel.txt = @"string of text";

Why does the string need the '@'? I'm guessing it's some kind of shortcut for creating an object?

它使用该字符串创建一个NSString对象,而不是在没有'@'的情况下创建的标准c char *

在Objective-C中,语法@“foo”是NSString的不可变的文字实例。

Just an interesting side note... NSString literals created by using the @"..." notation are not autoreleased . They essentially just hang around until your program terminates.

Just a caution that if you want to maintain control over whether or not this object gets released (freed) down the road you may want to consider using something like:

[NSString stringWithString:@"..."]; 

...instead. This would create an autoreleased version of the same string that will be freed from memory next time the "autorelease pool is drained".

Just food for thought.

Cheers-

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM