Catching NS_AVAILABLE_IOS while coding

不想你离开。 提交于 2019-12-23 18:46:53

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!