The simplest way to create a string object in source code is to use the Objective-C @"..." construct:
NSString *temp = @"/tmp/scratch";
Note that, when creating a string constant in this fashion, you should use UTF-8 characters. Such an object is created at compile time and exists throughout your program’s execution. The compiler makes such object constants unique on a per-module basis, and they’re never deallocated, though you can retain and release them as you do any other object. You can also send messages directly to a string constant as you do any other string:
BOOL same = [@"comparison" isEqualToString:myString];
这是来自 Creating Strings 的引述在 ObjC 文档中。
我在 applicationA 中测试了不同的 @""字符串,还有 applicationA 使用的 libB。 所有使用string=@"..."方式初始化的、内容相同的@"",都指向同一个内存地址。
因此,我不明白“per-module basis”的含义,“per-module”是什么意思?基于库?基于应用程序?基于文件?
最佳答案
出于 Mac OS X 和 iOS 开发的目的,一个模块相当于单个 .m/.mm/.c/.cpp 文件。
关于objective-c - NSConstantString 对象的唯一性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10928012/