19

Is it possible to create an own obj-C Cocoa Touch framework which can be used by other developers? And furthermore can you protect this framework?

1
  • 32
    Dust and fingerprints.
    – mipadi
    Commented Aug 19, 2009 at 14:51

9 Answers 9

17

I've created templates for Xcode 4 that allow you to build universal iOS frameworks (which work in both device and simulator).

Once the templates are installed, you simply select "Static iOS Framework" when creating a new project and it does the rest. It also works with unit tests.

https://github.com/kstenerud/iOS-Universal-Framework

2
  • Thank you for such a solution, it saved me some time. Commented Dec 26, 2011 at 14:28
  • @karl any plans upgrading your template ?
    – yunas
    Commented Jul 14, 2015 at 13:24
14

You can create a static library. There is an option in the XCode project chooser to do this. You'll have to distribute the compiled static library file and the header files to users of your library. Your actual implementation files (.m) do not need to be distributed.

GHUnit does a good job of this - packaging up the libraries for both simulator and device - so I recommend looking at this project. (I also recommend using this library for unit testing :-)

1
6

The frameworks in Objective C are typically just C / ObjC code and a bunch of classes, nothing amazingly special. As such, you can create your own if you'd like, and then just include that in your project when you build it. The iPhone doesn't care about the difference, it just knows to put all that code into your app, along with everything else.

Have a look at the Framework Programming Guide on Apple's website. It will get you started. Essentially what you'll do is create a Framework project in XCode and then go from there.

As for "protecting" your framework, I assume you mean making your code unreadable. I'm not sure if and how you can do this, but perhaps Apple's guide will say something about it.

3

Yes you can create frameworks for use with Cocoa Touch.

However there are these caveats:

  1. has to be a statically linked libary, no dynamic loading (dyld) for us
  2. should be a combined (lipo) library for i386 (simulator), arm6 and arm7
  3. you need to hack a bundle project into a framework
  4. you should embed (small and few) images into the library so that the developer does not have to mess around with resources but just drags/drops it into his project
  5. ... or if you have large and many images build a bundle with these

I have guides for these things on my site.

1+2 = http://www.drobnik.com/touch/2010/04/universal-static-libraries/

The other links you have to google because this site does not let me post more than one URL.

2
  • 1
    It does let you post more than one url.
    – Brandon
    Commented Nov 30, 2010 at 13:15
  • with swift we can't create static library the only would be creating a framework.so framework is basically collection of static and dynamic libraries but dynamic library we shouldn't use as dynamic linking is opposed to apple rules.so swift project is turned into framework it has to contain static library its quite contradicting. Commented Mar 11, 2017 at 16:08
2

You could make a static library available as binary (i.e. rudimentary "protection") to third parties, but not a dynamic one, as Apple's App Store policy prevents dynamic linking.

1

Take a look at a worked example for static libraries given at this site

0

If you're going to do it, in my opinion JSON.framework is a great example to follow. To hide/obfuscate the source code is a different story, and a different question entirely,

0

When creating a new project, navigate to iOS > Framework & Library > Cocoa Touch Framework, it's as simple as that. When you are successfully compile, .framework will be created under Products folder in XCode. Right click to show in Finder, and you can find the output.

-2

It's unlikely this will work the way you want it to because the other developers won't be able to use your framework. This StackOverflow Question explains why.

1
  • 1
    You are assuming that a framework will automatically imply using a dynamic library which is incorrect. You can build a framework around a static (universal) library, hence it does actually work perfectly fine.
    – Till
    Commented Mar 21, 2011 at 17:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.