What is difference between these 2 macros?
开发者_高级运维What is the difference between
__IPHONE_OS_VERSION_MAX_ALLOWED
and
__IPHONE_OS_VERSION_MIN_REQUIRED
Which should I use to detect old/new SDKs, like
#if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_3_2
__IPHONE_OS_VERSION_MIN_REQUIRED
is set to the Deployment target, which represents the version the user must minimally run to install your app. __IPHONE_OS_VERSION_MAX_ALLOWED
is set to the SDK version you're compiling against, although that doesn't mean your app won't run on newer versions though, but you can use it to check whether some OS features are available.
For instance, since iOS 3.2 we have the UIBezierPath
class. If you're compiling against SDK 3.1 (to test it in the iPhone Simulator presumably), this new class is not available so the compiler will give you a warning that the class doesn't exist. Fair enough, but we don't want to comment that specific code every time we build it against the older SDK, just for a simulator test. We just want to hide these blocks of code and that's made possible by those macro's.
Please read this article on Cocoa with Love for further explanation, tips and tricks.
精彩评论