1

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.

Mark Adams
  • 30,776
  • 11
  • 77
  • 77
slaterjohn
  • 249
  • 2
  • 9

2 Answers2

4

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"];
}
Mark Adams
  • 30,776
  • 11
  • 77
  • 77
  • Hi Mark That looks like it's working, although i'm trying to run the app within the iOS 4.3 simulator and i get the following error "dyld: Library not loaded: /System/Library/Frameworks/CoreImage.framework/CoreImage Referenced from: /Users/JohnSlater/Library/Application Support/iPhone Simulator/4.3.2/Applications/C964F4D5-FAD1-4348-895D-551FBD923915/SXIWalls.app/SXIWalls Reason: image not found " Which i'm starting to think is because the CoreImage framework altogether isn't available in iOS4. How would i go about getting around this error? – slaterjohn Jan 06 '12 at 19:40
  • Hi guys, this actually answered that question http://stackoverflow.com/questions/8385444/weak-linking-multiple-frameworks-for-iphone-apps-weak-framework Mark answered the first question correctly, cheers Mark :D – slaterjohn Jan 06 '12 at 19:48
1

Swift:

if let filter = CIFilter(name: "CIComicEffect")
        {
            // Filter exist
        }
        else
        {
            // Filter does not exist
        }
sabiland
  • 2,526
  • 1
  • 25
  • 24