106

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?

Proud Member
  • 38,700
  • 43
  • 143
  • 225
  • 22
    Unix exe file :-) – Besi Nov 16 '11 at 08:14
  • 6
    If you really want to be helpful to iOS developers, open-source it! – Kaan Dedeoglu Jul 15 '13 at 14:43
  • 4
    @KaanDedeoglu - There are pros and cons for users in both scenarios. Personally, I prefer a reasonably priced closed-source, everything is well documented, supported, and just works framework to an open-source, unsupported and undocumented framework. Rare is the open-source framework that is actually anywhere near well documented AND actively maintained. – ArtOfWarfare Sep 19 '13 at 10:07

3 Answers3

113

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.


Update:

Check out the link featherless added below -- it is much more recent and all on one page: http://github.com/jverkoey/iOS-Framework. It also lays out the issues with several other approaches. This is the guide I now follow when trying to remember what to do when setting up a new framework. :)

Update2 (with Xcode 6 release)

There is a option, exactly that you a re looking for: Universal Framework for iOS!

Will be my code visible to others? A: No. This Framework will export a compiled binary, so anyone can see inside it. You can make the same for some other files, like XIBs.

Why I need this? A: This is for developers/teams that want to share their codes without shows the entire code (.m/.c/.cpp files). Besides this is for who want to organize compiled code + resources (images, videos, sounds, XIBs, plist, etc) into one single place. And this is also for that teams that want to work together above the same base (framework).

(c) http://blog.db-in.com/universal-framework-for-ios/

Community
  • 1
  • 1
Jay Peyer
  • 1,999
  • 1
  • 18
  • 17
  • 1
    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? – Proud Member Oct 31 '10 at 21:44
  • 3
    Just to come back to this, as of Xcode 4 -all_load linker flag in the "Other Linker Flags" build setting is not required. -ObjC is the only flag you need. – Daniel Jun 22 '12 at 14:39
  • You're right Daniel, one of the more recent versions of LLVM/Clang fixed this. Thanks! – Jay Peyer Jun 22 '12 at 15:04
  • Love the github link to the iOS Framework, +1 – sbonami Oct 24 '12 at 22:43
  • Note: If you have Xcode 4.5, you will need a small modification to the tutorial as documented here: http://stackoverflow.com/questions/13571080/cant-change-target-membership-visibility-in-xcode-4-5 – Lolo May 10 '13 at 05:41
  • Is their a tutorial for a dynamic Framework somewhere? When you add a reference to 'Foundation.Framework' it is being linked dynamically and not statically as described in this tutorial. do you know of any dynamically linked framework capability? – Itay Levin Feb 04 '14 at 06:22
  • @ItayLevin Dynamic libraries (not including those created by Apple) aren't supported for apps that will be submitted to the App Store. See this question: http://stackoverflow.com/q/4733847/322748 – Jay Peyer Feb 04 '14 at 21:11
  • Is there any article that is more recent and references Xcode 6 along with the iOS Framework Project template that comes with Xcode 6 and iOS 8? – Danchez Nov 03 '14 at 02:13
  • This all links works only with objective-C . Now that swift is stable, we need some articles based on swift based frameworks. – Shane D Jun 16 '16 at 06:36
  • "This Framework will export a compiled binary, so anyone can see inside it". That blog post needs lots of proofreading. – Vlad Jun 19 '16 at 07:57
51

This guide is a bit more recent for creating iOS static frameworks:

https://github.com/jverkoey/iOS-Framework

featherless
  • 2,050
  • 19
  • 19
9

There is also a template for XCode 4 that will let you create iOS static framework projects.

Greg
  • 9,304
  • 5
  • 39
  • 62
  • do you know of projects that have been released with this method? – Tomen Nov 07 '11 at 11:37
  • No, I don't. I'm working on one that we're thinking of releasing this way, but I'm not sure whether that's what we'll go with in the end. – Greg Nov 07 '11 at 23:44