Search code examples
objective-ciosios5ios4backwards-compatibility

iOS5 classes on iOS4


I'd like to use some classes introduced in iOS 5 in an app that also runs on iOS 4. I understand how to use respondsToSelector: to selectively invoke new methods on the newer OS versions. What is the equivalent to determine, at runtime, whether the class exists.


Solution

  • if (NSClassFromString(@"ClassName") != nil)
    {
        // use class
    }
    else
    {
        // not available, deal with it.
    }