8

For example there is a new class in iOS 7 that does not exist in iOS 6. I want to use this new class. My app must stay compatible with iOS 6. So I read in some places that you can now do this:

if ([NSURLSessionConfiguration class]) {
    // only in iOS 7        
} else {
    // do it iOS6 way
}

Is this safe to do in any iOS 6 version or should we still use NSClassFromString?

openfrog
  • 40,201
  • 65
  • 225
  • 373
  • possible duplicate of [Weak Linking - check if a class exists and use that class](http://stackoverflow.com/questions/3057325/weak-linking-check-if-a-class-exists-and-use-that-class) – ldiqual Sep 21 '13 at 21:22
  • 1
    Duplicate but I like this question more. It's more succinct and there's actually code in the question. – Joshua Gross Sep 21 '13 at 21:25

1 Answers1

9

YES, this is safe.

This is the correct and recommended way of checking to see if certain classes are available to be used.

Community
  • 1
  • 1
Dave DeLong
  • 242,470
  • 58
  • 448
  • 498