问题
I know how to change the lowest OS supported with IPHONEOS_DEPLOYMENT_TARGET
. I am currently developing under Xcode 4.5 and using the iOS 6.0 SDK.
What I'd like to do is find a way to throw a warning in compilation whenever I use code that is marked: NS_AVAILABLE_IOS(6_0)
So that I can make sure that I don't miss any "Yes, but you're on iOS 5 so don't use this code" areas that will crash the user's device.
回答1:
NS_AVAILABLE_IOS(6_0)
is defined as __attribute((unavailable))
when the SDK is lower that 6.0… but is defined as nothing when the SDK is 6.0 or greater.
So as long as you compile with the SDK 6.0, you will have conceptually #define NS_AVAILABLE_IOS(6_0) /* noop */
so you won't be able to detect anything.
The only option is to redefine IPHONE_OS_VERSION_MAX_ALLOWED
to trick the compiler and make it think it uses an older SDK, but i am not even sure that it is possible to redefine it soon enough before the NSObjCRuntime.h
and AvailabilityMacros.h
headers are included.
来源:https://stackoverflow.com/questions/12691673/catching-ns-available-ios-while-coding