The Lazy Coder
The Lazy Coder

Reputation: 11828

NSArray support like C++ (odd code example)

I have been doing objective c for a couple years, my co-developer however has only just begun, but his virgin eyes found something that I hadnt even dreamed of.

He used an NSArray like a C++ pointer array

self.myArray = [NSArray arrayWithObjects:@"object1",@"object2",@"object3",nil];
NSString *object1 = self.myArray[0];
NSString *object2 = self.myArray[1];

Now while this does actually work, I cant find reference to it.

I also have not found any examples of it in use.

Does anyone have any insight into why this works. Or can lead me to some documentation to the usage.

I had no idea that you could use the NSArray like an old c++ array ??

Upvotes: 2

Views: 164

Answers (1)

Karthik T
Karthik T

Reputation: 31952

This link does show an example of access by index, even thought its not quite talking about that.. Im new to Objective C, so what is it that surprises you exactly?

Edit: You are right, this syntax appears to be a recent change with XCode 4.5 - Scroll to about half way.

Upvotes: 3

Related Questions