iOS "@" notation instead of initializer?

dantastic

macrumors 6502a
Original poster
Jan 21, 2011
569
645
I have just started coming across this use of an @ notation instead of a proper type initializer. Being quite simply an @ I've not been able to google any more info about it.

What is is, I've found these

@15 -> creates a NSNumber
@[@"one", @"two", @three"] -> creates a NSArray

Do anyone know where to find a bit more documentation around this? what the full capabilities are and any drawbacks?
 

dantastic

macrumors 6502a
Original poster
Jan 21, 2011
569
645
Thanks Matt!

That's super cool stuff I must say. Now I know what to do today! :rolleyes:
 

MattInOz

macrumors 68030
Jan 19, 2006
2,761
0
Sydney
Used it on a parent NSMangedObject to access the child objects in an ordered one to many relationship. Makes dealing with model objects in the controller easier and cleaner.
 

Duncan C

macrumors 6502a
Jan 21, 2008
853
0
Northern Virginia
Used it on a parent NSMangedObject to access the child objects in an ordered one to many relationship. Makes dealing with model objects in the controller easier and cleaner.
Cool. I'll have to bear that in mind.

To add subscripting support to array-like objects, you have to add objectAtIndexedSubscript: and setObject:atIndexedSubscript: methods to your class, right? Anything else that you need to do?

And what about support for dictionary subscripting? For those, I gather you implement objectForKeyedSubscript: and (for mutable dictionaries) setObject:forKeyedSubscript: