ioscocoacore-imagerespondstoselector

Checking CIFilter is available in current iOS


I would like to use some of the functionality of iOS5 but still build for iOS4 compaitibly but i'm having an issue. Typically i would use the respondsToSelector: but i'm not exactly sure whether this is the correct method, or if it is what exactly i should insert.

I'm trying to use CIFilter which, from what i understand, is only available within iOS5+, how would check to see whether this is available within the currently installed OS?

Thanks in advanced.


Solution

  • Try using NSClassFromString() to determine if the class exists in the current version of iOS.

    Class filterClass = NSClassFromString(@"CIFilter");
    
    if (!filterClass)
    {
        // Must be less than 5.0. CIFilter doesn't exist.
    }
    else
    {
        // CIFilter is available
        CIFilter *filter = [filterClass filterWithName:@"somefilter"];
    }