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?
9 Answers
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.
-
Thank you for such a solution, it saved me some time. Commented Dec 26, 2011 at 14:28
-
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 :-)
-
2As another example, Core Plot's Cocoa Touch variant compiles as a static library: code.google.com/p/core-plot Commented Aug 19, 2009 at 17:19
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.
Yes you can create frameworks for use with Cocoa Touch.
However there are these caveats:
- has to be a statically linked libary, no dynamic loading (dyld) for us
- should be a combined (lipo) library for i386 (simulator), arm6 and arm7
- you need to hack a bundle project into a framework
- 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
- ... 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.
-
1
-
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
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.
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,
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.
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.
-
1You 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.– TillCommented Mar 21, 2011 at 17:34