iphone – NSString stringWithString VS @“string”

我只是很好奇,以下两个代码有什么区别吗?

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.

相关文章

我正在用TitaniumDeveloper编写一个应用程序,它允许我使用Ja...
我的问题是当我尝试从UIWebView中调用我的AngularJS应用程序...
我想获取在我的Mac上运行的所有前台应用程序的应用程序图标....
我是一名PHP开发人员,我使用MVC模式和面向对象的代码.我真的...
OSX中的SetTimer在Windows中是否有任何等效功能?我正在使用...
我不确定引擎盖下到底发生了什么,但这是我的设置,示例代码和...