I read all about the new Objective-C literals, and used Xcode to convert my old code, but the indexing code didn't change. I changed it by hand but then it wouldn't compile. I saw a post that said we have to wait until iOS 6, but I want the indexing NOW!
Is there any solution?
Well, there is a way to do it! Add the indexing methods as a category to NSArray and NSDictionary, and you can get the feature for most of the classes you'd want it for. You can read up on ObjectiveC literals here. And thanks to James Webster's solution for @YES and @NO you can use them properly in your projects now too! (the technique)
1) Create the Interface files
2) Create the Implementation files // see edit below before doing this - you can skip this
3) Add the Interface files to your pch file for global use, or add them as needed to .m files
4) Rebuild, then add the below files to verify that it all works
EDIT: Well, according to a key llvm/clang Apple engineer, there is a library that already gets linked in with the implementations, so you just need the interface file:
Date: Mon, 20 Aug 2012 15:16:43 -0700 From: Greg Parker To: ... Subject: Re: How to make Obj-C collection subscripting work on iOS 5? ...
The compiler emits the same calls. The magic is in the increasingly inaccurately named libarclite ("It's Not Just For ARC Anymore™"), which adds implementations of the subscripting methods at runtime if they don't already exist.
IIRC there are some subscript-able classes that libarclite does not upgrade (NSOrderedSet, maybe?) so you still need to test thoroughly on older deployment targets.