我只是很好奇,以下两个代码有什么区别吗?
NSString * aString = [NSString stringWithString:@“a string”];
NSString * aString = @“一个字符串”;
我想知道当你采用后一种方式时到底发生了什么.
解决方法
两者都指向在编译时创建的文字字符串.
尽管stringWithString表明它是自动释放的,但文字字符串永远不会被释放.
在这里查看我的相关帖子:
Difference between NSString literals
来自apple docs @ https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Strings/Articles/CreatingStrings.html
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.