4 ms·
Any idea why literal syntax would only be for OS X?
by MaxGabriel 14y ago
Any idea why literal syntax would only be for OS X?
- cageface 14y agoIt has to be exposed in the SDK too. You can hack in some iOS support via a category but you'll have to use 4.5 if you want the real deal for iOS.
- ryanpetrich 14y agoI requires runtime support that hasn't yet shipped on a public version of iOS.
- hboon 14y agoIsn't it a compile time feature?
- msbarnett 14y agoOnly partially. Mike Ash goes into some detail on his excellent blog: http://www.mikeash.com/pyblog/friday-qa-2012-06-22-objective-c-literals.html http://www.mikeash.com/pyblog/friday-qa-2012-06-22-objective... Long story short, some of it is compile time, but some of it involves classes in Foundation (like NSArray and NSDictionary) implementing new methods (like objectAtIndexedSubscript). iOS needs a base SDK update before those methods will be available there. Or you could monkey-patch them in with a category yourself in the meantime.
- hboon 14y agoLiterals and object/container subscripting are different things, even though they appear at the same time. Container literals should be compile time too and available to all versions of iOS (or at least v4 and above). I also think it should be possible to support container (NSArray, NSDictionary) subscripting for foundation classes at compile-time for all versions even if the new functions aren't around. They just have to translate to the existing functions. I bet they do this too[1] (upvoted you, it is a very informative link). Edit: some more thoughts. [1] No, they don't do that in v4.4. But maybe they will in a future version of Xcode.
- woadwarrior01 14y agoThanks for the link. I was wondering if they'd implemented type-inference to check what method to call for the indexing operator since the operand could be either an NSArray or a NSDictionary. It turns out they've elided the whole problem altogether by doing this at runtime with new methods. Given how dynamic objective-c is, this seems like the best way to go about it.
- hboon 14y agoPretty sure the release note is incorrect. I just tried and it works. Also search for "Objective-C Feature Availability Index" in the docs.
- Reflejo 14y agoI just tried it in the iOS simulator and literals work. @[...] => NSArray, @{...} => NSDictionary, @# => NSNumber