objective-c - NSArray 对象里存储的元素为什么可以通过“数组下标”进行访问?
ringa_lee
ringa_lee 2017-04-21 11:17:18
0
2
846

NSArray 不是OC里的内置数据类型,只是Cocoa库中的一个常用类。 那么用objectAtIndex方法,通过传入index参数进行访问NSArray里的元素,例如[arr objectAtIndex:5]即调用方法,这是可以理解的。但是arr[5]这种写法,为什么是属于合法的呢?按理说NSArray不是语言层的东西,应该是更高层级的,怎么还能有特殊的方法调用?

ringa_lee
ringa_lee

ringa_lee

reply all(2)
Peter_Zhu

This is a new feature of Objective-c LLVM 4.0.

Recommended reference article: http://blog.csdn.net/kindazrael/article/details/8091201

巴扎黑

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?

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!