Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to conditionally link frameworks based on their availability in Xcode using Objective-C

I'm developing an objective-c framework based off Cocoa touch and am looking at other frameworks for parsing data, both for JSON and XML.

I want to be as easy for the developer using to use my framework out of the box and am wondering what the best way to include third party frameworks conditionally. I want to give credit where credit is due, so I don't want to include the other projects with the distribution, but I'd like the developer be able to add a framework (or even just a bunch of classes) like SBJson or Touch XML and have my codebase to see the included codebase and use it with the added functionality it provides. Enabling the framework through some kind of config file, or in the project settings is also an option, but is less ideal.

  1. What is the best way to do this with the compiler settings? I have seen a lot of developers switching included frameworks from "Required" to "Optional", but I don't think either SBJson or Touch XML are compiled down to or implemented using an objective-c framework package (.framework) or a C static library (.a) and thus wouldn't be able to take advantage of this.

  2. How would one conditionally implement this in code? For instance SBJson's header is imported via a #import "SBJson.h" compiler directive, but this will fail if the required header isn't found.

like image 449
KellyHuberty Avatar asked Dec 24 '12 23:12

KellyHuberty


1 Answers

You can include the .h but when using an object from it you need to call it with NSClassFromString

like image 170
CiNN Avatar answered Nov 07 '22 12:11

CiNN