Build error when using iOS6 If Statement in xCode

2019-09-18 01:53发布

问题:

I am building a project in XCode 5 with Deployment Target 6.1 and SDK 7.0 but I am getting an error on this line:

 if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) {

The error says *Use of undeclared identifier 'NSFoundationVersionNumber_iOS_6_1*

回答1:

Your code should work in iOS7. Please cross check your Base SDK version once again.

Project Target -->Build Settings -->Base SDk

Its a part of Foundation.framework NSObjCRuntime.h class. So make sure you have the Foundation.framework under Project Target -->Build Phases -->Link Binary With Libraries section.

If it's not availabe, click on the + button and add the Foundation.framework in to your project.

Note:

This can happen when you try to run code built for iOS 7 Base SDK on Xcode 4.x, or if you compile against an older Base SDK in Xcode 5.

The solution is to define what isn’t defined manually using a Macro. Add this to every class that’s complaining and you should be fine.

#ifndef NSFoundationVersionNumber_iOS_6_1
#define NSFoundationVersionNumber_iOS_6_1 993.00
#endif

This tells the compiler to define the value if it’s not there, so it has no reason to complain.