views:

65

answers:

1

We have an idea for an framework or library that will be very helpful for any iOS developer. So we're seriously thinking about switching from app development to framework/library development.

But when we want to charge for the library/framework, we must protect the code somehow. How can we build a framework in such a way that the user of our framework can't see the source code, similar to how we can't see the source code of Apples frameworks? They only ship the header files and some weird Unix exe file with the compiled framework, I guess.

Or if it is not possible to make an compiled framework / library that other iOS developers can use without beeing able to copy&paste our source codes, then is there a way to obfuscate the objective-c code?

+5  A: 

Yes, it is possible to build frameworks so the user of the framework can't see the source code.

Check out these articles (I've successfully used the first one to create frameworks in the past -- the later articles are updates to the original):

http://www.drobnik.com/touch/2010/04/making-your-own-iphone-frameworks/

http://www.drobnik.com/touch/2010/05/making-your-own-iphone-frameworks-in-xcode/

http://www.drobnik.com/touch/2010/10/embedding-binary-resources/

To use the framework, your users would just drag the .framework bundle into Xcode. They will be able to see the header files you copy into the bundle (see the articles above), but not the source (as it's not included -- only the compiled output is in the bundle).

This can also be a great way to distribute code that is used for multiple projects within your company.

JP
Thanks mate! Apple won't reject an app because of this trick? Did you actually get an App approved on the App Store that used such an framework?
BugAlert
Yes, we have apps approved on the app store that do this. Apple does not allow _dynamic_ frameworks, but these are static and so okay. This method is very similar to creating a "Cocoa Touch Static Library" using the built-in template in Xcode. The main difference is that by creating a framework bundle, your static library and header files are easier to import into projects (it sets up the search paths for you), and everything is much more organized in Xcode. We also do this for open source code we're utilizing, as it is cleaner and lets us skip compiling the code with every clean-build cycle.
JP
Also, just a note to ensure your success with this: If you have any Categories in your code in the static library/framework, you must put -ObjC and -all_load in the "Other Linker Flags" of your target (_in the project where you're using the framework_). See http://stackoverflow.com/questions/1147676/categories-in-static-library-for-iphone-device-3-0 (and many other places on the web) for more info.
JP