objective-c - NSConstantString 对象的唯一性

标签 objective-c nsstring

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/

相关文章:

objective-c - 在动态创建的类中执行协议(protocol)类方法

ios - 如何使用 collectionView 自动滑动图像

objective-c - boolean 到 NSString

ios - 如何从 NSString 获取特定字节长度的子字符串

swift - 无法将类型 'Swift._NSContiguousString' 的值转换为“NSNumber”

objective-c - 如何在沙盒应用程序中获取用户主目录?

ios - iOS 8.1 中不生成设备 token

iphone - 使用委托(delegate)在选项卡之间传递数据不起作用

objective-c - iOS - 将文本 append 到应用程序包中的文件

objective-c - 为什么 [NSMutableString stringWithString : @""] work?