kmell96
kmell96

Reputation: 1465

Objective-C NSArray Access

It seems that in Objective-C there are two ways to access an NSArray. I could access the 'i'th element of NSArray 'array' by:

array[i]

or

[array objectAtindex:i]

Is there any functional difference between these two options?

Upvotes: 0

Views: 113

Answers (1)

Arc676
Arc676

Reputation: 4465

There is no a slight difference.

The shorter version uses objectAtIndexedSubscript: as opposed to objectAtIndex:. These methods are identical in their effect, but you can implement objectAtIndexedSubscript: in your own classes to allow element access with the [index] syntax.

The shorter version is probably an instance of the "modern Objective-C syntax".

See this link for some more information on the modern syntax and other changes.

See this other link for information on Objective-C literals, courtesy of @luk2302.

Upvotes: 2

Related Questions