gpt4 book ai didi

iphone - NSString 字符串与字符串 VS @"string"

转载 作者:可可西里 更新时间:2023-11-01 05:47:03 25 4
gpt4 key购买 nike

我只是好奇,下面两个代码之间有什么区别吗?

NSString *aString = [NSString stringWithString:@"a string"];

NSString *aString = @"字符串";

我想知道当你采用后一种方式时到底发生了什么。

最佳答案

两者都指向在编译时创建的文字字符串。

即使 stringWithString 表明它是自动释放的,文字字符串也永远不会被释放。

在这里查看我的相关帖子:

Difference between NSString literals

来自苹果文档 @ 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.

关于iphone - NSString 字符串与字符串 VS @"string",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9579295/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com