Reputation: 262464
After updating XCode to 4.5, it also updated to iOS SDK 6 (and removed the old SDK, I think). I got the old 5.1 simulator to install again (from the Downloads preference), but is there a way to also get compile-time errors that match the deployment target (5.1)?
Right now, I can compile calls to iOS6 methods, only to have them fail at runtime on device or simulator.
Is there a way to get errors or warnings at compile time? And maybe remove the new methods from code completion?
Upvotes: 2
Views: 401
Reputation: 3961
Clang does not support such warnings therefore it's impossible to generate them at compile time.
However, it doesn't mean it's not possible, because hopefully Apple adds availability macros to almost every public API. So 3rd party parsers are able to determine whether method is available or not. E.g. AppCode can do this. It'd generate warnings like this:
Upvotes: 5
Reputation: 6023
No, it is your responsibility to check availability of classes, methods, constants and enumerations at runtime, when there is a chance that your deployment target doesn't have them.
if ([MyClass class] == nil) { }
if (![MyClass instancesRespondToSelector:@selector(foo)]) { }
if (&kSomeConstant == NULL) { }
Also, if a whole framework may not exist, link to it optionally (weak). Finally, test on real devices with every OS version you support.
Old versions of Xcode are available to install side by side, but they will fail to build your project if you used any iOS 6 frameworks, classes, methods, etc.
Upvotes: 3