编码时捕获NS_AVAILABLE_IOS [英] Catching NS_AVAILABLE_IOS while coding
问题描述
我知道如何更改支持的最低操作系统IPHONEOS_DEPLOYMENT_TARGET
。我目前正在使用Xcode 4.5开发并使用iOS 6.0 SDK。
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.
我想要做的是找到一种方法在编译时发出警告,每当我使用代码时标记为:
NS_AVAILABLE_IOS(6_0)
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)
这样我就可以确保我不会错过任何是的,但你在iOS 5上所以不要使用此代码会导致用户设备崩溃的区域。
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.
推荐答案
NS_AVAILABLE_IOS(6_0 )当SDK低于6.0时,
被定义为 __属性((不可用))
但是当SDK为6.0或更高版本时,它被定义为空。
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.
因此,只要您使用SDK 6.0进行编译,您就可以在概念上 #define NS_AVAILABLE_IOS(6_0)/ * noop * /
所以你将无法检测到任何东西。
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.
唯一的选择是重新定义 IPHONE_OS_VERSION_MAX_ALLOWED
欺骗编译器并让它认为它使用较旧的SDK,但我甚至不确定它是否可能o在 NSObjCRuntime.h
和 AvailabilityMacros.h
标题之前很快重新定义它。
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.
这篇关于编码时捕获NS_AVAILABLE_IOS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!