What does a square-bracketed index after an NSArray mean? [duplicate]

梦想的初衷 提交于 2019-12-02 04:50:49
Josh Caswell

Your understanding is completely correct; you're just missing one bit of syntax. Subscripted access of NSArrays with the array[index] form is part of the "collection literals" feature introduced by Clang a little while back.

It's transformed by the compiler into a call to [array objectAtIndexedSubscript:index].

As usual, in writing this out, it makes sense. It's literally saying, that if cardB matched cardC, use an index of [1] (cardC), if not, use an index of [0] (cardB)

So,

cardA.contents = cardB.contents // if does NOT match
cardA.contents = cardC.contents // if matches

(based on the index).

Duh.. Sorry for a silly question...

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!