Checking CIFilter is available in current iOS

827 Views Asked by At

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.

2

There are 2 best solutions below

2
On BEST ANSWER

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"];
}
0
On

Swift:

if let filter = CIFilter(name: "CIComicEffect")
        {
            // Filter exist
        }
        else
        {
            // Filter does not exist
        }