ARC和非ARC NSString初始化 [英] ARC and Non-ARC NSString Initialization
问题描述
最近,我一直在我的Objective-C / iOS程序中使用自动引用计数,并且一直享受这个功能。
Lately, I have been using Automatic Reference Counting in my Objective-C/iOS programs, and have really been enjoying the feature.
理解它是初始化 NSString
的正确方法。我看到这个方法用于ARC和非ARC项目:
One thing I don't understand about it is the proper method to initialize an NSString
. I have seen this method used with both ARC and non-ARC projects:
NSString *myClassicString = [[NSString alloc] initWithFormat:@"My great non-ARC string!"];
我还发现以下方法可用于初始化 NSString
在ARC,我更喜欢它,因为方便:
I have also found that the following method can be used for initializing an NSString
in ARC, and I prefer it because of the convenience:
NSString *myARCString = [NSString stringWithFormat:@"My new simple initialization string!"];
这两者之间有什么区别吗?有正确的方法吗?是否更好?
Is there any difference between these two? Is there a proper way? Is either one better?
推荐答案
两种方法是一样的。在 NSString
初始化中,无优于其他。
Both methods are the same. None is better than the other in term of NSString
initialization.
这篇关于ARC和非ARC NSString初始化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!