ignore ios8 code in xcode 5 compilation

I’ve got a team working on some IOS code. One developer (me) has Xcode6-beta with a few lines of IOS8 specific code. When another developer with Xcode5 builds it for IOS7, compilation fails, because the IOS8 SDK doesn’t exist for him.

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0){
    // ios8 code
} else {
    // ios7 and less way
}

Is there a way to ignore the IOS8 code in Xcode compilation based on the SDK or Xcode version, such that it compiles?

  • Business card reader or OCR Library for iPhone SDK
  • Xcode - Create csv/spreadsheet file
  • XCode Build not updating JS and HTML
  • Accelerometer & Calibration - iPhone SDK
  • iOS 5.1 with Xcode 4.2 and retina in iPad 3
  • How do I disable NSLog?
  • 2 Solutions Collect From Internet About “ignore ios8 code in xcode 5 compilation”

    Yes, you can do this using directives:

    #ifdef __IPHONE_OS_VERSION_MIN_REQUIRED
    // target is iOS
        #if __IPHONE_OS_VERSION_MIN_REQUIRED < 80000
        // target is lower than iOS 8.0
        #else
        // target is at least iOS 8.0
        #endif
    #endif
    

    This is similar to commenting out unneeded lines of code but automatically. Compiller does not include everything which is stored 8.0-specific part of the if-statement.

    This link is great. But in short ask the object if a certain method respondsToSelector:

    if ([self.<object_name> respondsToSelector:@selector(<method_in_question>)]) {
        [self.<object_name> <method_in_question>];
    }
    

    This is much more dynamic than checking the actual OS version. Good luck!