In other words, use literals but target for iOS 5.
I am aware of this but that post is not conclusive.
In other words, use literals but target for iOS 5.
I am aware of this but that post is not conclusive.
You can switch the compiler out, but it doesn't work as you might think (I tried it just now). There are a few requirements of the compiling SDK for using this new syntax (i.e. it will work on previous iOS versions, but you need to compile it with the iOS 6.0 SDK). I don't think I am allowed to discuss them here at the moment, but they are covered in detail in the "Modern Objective-C" WWDC 2012 video.
Basically, you will have the syntax, but the libraries will not know how to respond to it.
There is an alternate theory though...that I just didn't do it right ^^;
In the end though, you don't have to use 4.3 to deploy to 5.x apps. So my suggestion is just upgrade, there is really no downside to it (unless you are deploying an app soon, but in that case it would just be a hassle to convert everything since I assume you are almost done).
EDIT (2 months later now iOS 6 is public). You can definitely use categories to get around the SDK requirements of the new objective-c literal syntax. Add categories on NSArray
and NSDictionary
for - (id)objectAtIndexedSubscript:(NSUInteger)idx
and - (id)objectForKeyedSubscript:(id)key
respectively that just return objectAtIndex:
and objectForKey:
(that is what they do anyway in iOS 6). Also for NSMutableArray
and NSMutableDictionary
add category methods for - (void)setObject:(id)obj atIndexedSubscript:(NSUInteger)index
and - (void)setObject:(id)obj atIndexedSubscript:(NSUInteger)index
respectively that simply add the object if it doesn't already exist, and replace it if it does.
One catch: The definitions of YES
and NO
changed in iOS 6 to accommodate boolean literals for NSNumber
. So you need to do the following:
#if __has_feature(objc_bool)
#undef YES //Before it was (BOOL)1
#undef NO //Before it was (BOOL)0
#define YES __objc_yes
#define NO __objc_no
#endif
The reason is that in the new syntax already has a definition for the @( ... )
syntax (boxed expressions) and the old definition would resolve to @(BOOL)1
which is an error.