objective c - Whats the difference between array[index] and [array objectAtIndex:index]? -
i noticed both array[index] , [array objectatindex:index] work mutable arrays. explain difference between them? in terms of performance, , 1 best practice?
none. that's part of clang extensions objective-c literals, added 2-3 years ago.
also:
array-style subscripting
when subscript operand has integral type, expression rewritten use 1 of 2 different selectors, depending on whether element being read or written. when expression reads element using integral index, in following example:
nsuinteger idx = ...; id value = object[idx];it translated call
objectatindexedsubscript:id value = [object objectatindexedsubscript:idx];when expression writes element using integral index:
object[idx] = newvalue;it translated call
setobject:atindexedsubscript:[object setobject:newvalue atindexedsubscript:idx];these message sends type-checked , performed explicit message sends. method used
objectatindexedsubscript:must declared argument of integral type , return value of objective-c object pointer type. method usedsetobject:atindexedsubscript:must declared first argument having objective-c pointer type , second argument having integral type.
Comments
Post a Comment