本文介绍了@[] 和 [NSArray arrayWithObjects:] 的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能的重复:
我应该更喜欢使用文字语法还是用于创建字典和数组的构造函数?

有什么区别:

NSArray *array = @[@"foo", @"bar"];

NSArray *array = [NSArray arrayWithObjects:@"foo", @"bar", nil];

其中之一是更稳定、更快还是其他什么?

Is one of those more stable, faster, or anything else?

推荐答案

这个文档没有直接提到效率,但确实提到了

This documentation doesn't mention anything about efficiency directly, but does mention that

NSArray *array = @[@"foo", @"bar"];

相当于

NSString *strings[3];
strings[0] = @"foo";
strings[1] = @"bar";
NSArray *array = [NSArray arrayWithObjects:strings count:2];

我必须假设在程序集级别,两者是相同的.

I would have to assume that at an assembly level, the two are identical.

因此唯一的区别是偏好.我更喜欢前者,打字更快,理解更直接.

Thus the only difference is preference. I prefer the former, it's faster to type and more direct to understand.

这篇关于@[] 和 [NSArray arrayWithObjects:] 的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 15:41