Can I develop my own objective-C Framework for Cocoa Touch Applications?

孤街醉人 提交于 2019-12-29 03:10:26

问题


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:


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:


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 :-)




回答3:


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.




回答4:


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.




回答5:


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.




回答6:


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




回答7:


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,




回答8:


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.




回答9:


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.



来源:https://stackoverflow.com/questions/1300457/can-i-develop-my-own-objective-c-framework-for-cocoa-touch-applications

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!