NSArray 不是OC里的内置数据类型,只是Cocoa库中的一个常用类。 那么用objectAtIndex方法,通过传入index参数进行访问NSArray里的元素,例如[arr objectAtIndex:5]即调用方法,这是可以理解的。但是arr[5]这种写法,为什么是属于合法的呢?按理说NSArray不是语言层的东西,应该是更高层级的,怎么还能有特殊的方法调用?
天蓬老师2017-04-21 11:19:18
This is a new feature of Objective-c LLVM 4.0.
Recommended reference article: http://blog.csdn.net/kindazrael/article/details/8091201
巴扎黑2017-04-21 11:19:18
The so-called syntactic sugar makes it more convenient for programmers to write. Almost all mainstream programming languages support such features. It is not a question of whether it is advanced or not. Shouldn’t the more advanced it be, the more trouble it will have? There is no such truth.
Going a step further, is there any difference between objectAtIndex and syntactic sugar? In the end, what the computer sees is 0 and 1, so what else is not syntactic sugar?