gpt4 book ai didi

ios - const NSString 和 static NSString 有什么区别

转载 作者:可可西里 更新时间:2023-11-01 05:31:02 24 4
gpt4 key购买 nike

我想使用类变量。以下两种方法效果很好,但我不知道它们之间有什么不同。

static NSString *str1 = @"str1";
NSString *const str2 = @"str2";
@implementation StrViewController

最佳答案

您可以将位置更改为 str1 指向的位置,但不能对 str2 执行相同的操作,因为它是一个 const 指针

这会起作用:

str1 = @"Hello";

虽然这不会:

str2 = @"Hello"; 

关于ios - const NSString 和 static NSString 有什么区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12815189/

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