How do I package components to use in multiple iPhone app? - iphone

I am working on a number of iPhone development projects and I am starting to refactor code and would like to be able to package it in a library or framework that I can reuse in different xcode projects for different iPhone applications. I looked at the New Project dialog in xcode and the only option I have under iPhone OS is to create an Application. I have also read somewhere in the iPhone SDK documentation that I cannot create my own framework to reuse in different iPhone apps. What is then the best way to package my reusable components? I went over the iPhone SDK documentation and could not find out. I could keep all my reusable classes in a dummy project and link to those source files from other projects (so I would have a single copy of the source to maintain), but that feels very clumsy.
Thank you,
fxt

Create your common code as a static library.
Drag the xcodeproj file into the groups and files section of the project you want to use it in.
Update the include path to point to the headers of your static library.
In the info pane for the project you want to use the static lib in add it as a direct dependancy.
This process makes it almost as easy to work with as a regular framework.

Unfortunately Apple does not allow frameworks for the iPhone development at this stage. You can either bundle your code in a static library or just the source files in such a way that can easily use them in multiple projects.
I use SVN and keep my reusable code in repositories so that I can easily include them in new projects as externals

Apple does not allow to create own framwork. But you can achieve your goal by creating static libary.
Here is important link for kick off Static library.
Have a look:
http://blog.stormyprods.com/2008/11/using-static-libraries-with-iphone-sdk.html

Related

how to create a static library or framework from a already available source code in iOS

My clients wants to use some of the already available features in my app into their app. But, i dont want to share my source code with them and vice versa. I found out from some googling that, we can do this by creating some static libraries or frameworks in iOS. Can anyone throw some light on how to create a static library or framework (which ever is better) out of my already available source code.
My preference is to use static libraries over Frameworks. You will provide your customers the library file (.a extension) and the header file(s) for the functions in it. They just need to install the files somewhere in their project tree, set the include path, add the library to the project and they are good to go.
Note that if you want them to use your lib in the Simulator as well as on device you will need to provide them two versions of the library, one for each.
For instructions on how to create and use an iOS static library see this site.
Just for your information:
I created a static framework for iOS according to jverkoey's instruction
A ton of thanks to Diney Bomfim for his excellent article on how to create a framework. This is exactly what i am looking for.
EDIT - The Link is NOT working anymore...

Are there best practices for sharing development code between iPhone and iPad app

I want to build two apps, one optimized for iphone and one for ipad.
both of these applications invoke server API calls and would share the same code for model objects, so I would like to share this code between my iphone and ipad projects.
I am using xCode 4, with a concept of workspace (which is supposed to allow sharing of code between projects) but I was wondering if I need to create another project for just the shared code.
Has anyone done this and care to share the best practices?
I prefer to share code across projects, be it for iPhone/iPad reuse or any other sharing scenario by leveraging a Static Library Project to house shared code, and used as a Target Dependency in all projects that consume it. In a bit more detail...
You can create a new Xcode Project with a Cocoa Touch Static Library template. This project can house all of the shared code between projects. Then, in any app in which you want to use the static library, you can add a project reference to the static library project by dragging the static lib project into the client project. In this client project, it's a good idea to add the static library as a Target Dependency build phase of the client project. This forces the shared library to be re-built anytime the client project is built. Then, you'll add the static library product to the "Link Binary With Libraries" build phase of the client project.
And, as one final caveat, you also need to tell the client project where the headers for the static library live. This is a result of static libs not containing their own headers like a Cocoa Framework on the Mac does. To do so, just find the "Header Search Path" build setting in the client project, and add the path to the static library headers. I've found it most useful to reference the ones produced by Xcode and placed in Derived Data (if you have Xcode configured to do so).
If you are going to build two separate applications, then you need to create one workspace with two iOS application projects and one static library project. The static library should contain all of your shared code, and the library should be included by both of your iOS application projects.

iPhone static lib

i want to share some code with other iOS projects. So I create static library.
When I use this library in other projects and use header file from that lib I get an error like No such file and Directory. Can any one tell me fixes of it.
Here I get reference for making static lib
http://www.amateurinmotion.com/articles/2009/02/08/creating-a-static-library-for-iphone.html
I downloaded that sample. It is also not working in my case. So please help me to fix that error.
Thanks in advance
My guess would be because the blog, whilst detailed, is probably a bit old now. Like anything there's a thousand ways to skin a cat.
You can now create frameworks for the iPhone sdk and include both simulator and device versions of the classes. Frameworks have the advantage that they can simply be dragged and dropped on Xcode to include them in a project. In addition I like to store my frameworks in version numbered directories so if I make changes, dependent projects can still use the old ones until I'm ready to update them.
I don't do it, but for the above reasons I'm not sure I'd drag and drop a libs project on a client project. To me the idea of a static framework is that it's independent on it's clients. Dropping it into client projects makes a connection between the two projects that is too tight.
Anyway do some searches on lipo and static frameworks. I also have so scripts in my project at https://github.com/drekka/dUsefulStuff that you mint find useful.

Best practices for MacOS/iPhone library cross compiling

I've build a static library working nice in a Cocoa Touch environment. Now I'd like to compile it also for Cocoa.. Can I have a single XCode project with different sdk targets? Is there some resource out there able to give hints about best the practices in this (and other) sense?
This last two months I have been working on exactly this task ( cross compiling static library for iPhone/Android/Mac OS/Linux/Windows...
It is certainly possible, a nice way, is adding an external xcode project as a target to your first xcode project. So you create a new "Active Configuration" for Mac OS X, iPhone and other platforms that you want to support.
Here, you can find a good tutorial about how to use a secondary Xcode project as a target of your main project to build a static library. It's a cool way because if you debug for example you still have all the symbols of the library, etc.
It can be done but it requires some manual tweaking of the build.
Start with the Xcode Build System Guide.
As an informal way of accomplishing this, you can create two separate projects and add references for exact same set of library source files to each project. Set one project to compile for Cocoa-Touch and the other for Cocoa. If both projects reference the same files, changes made in one project will be automatically reflected in the other. (If you have both projects open, Xcode will complain that the file has been changed by another app but otherwise it won't notice.)
I have a utility class that I continually dump new methods in. I add it to every project and just park methods as I need it. The new methods show up in old projects because the source files are shared across all the projects.

Best way to share iphone and mac code between projects

I realise that the view/controller stuff will be different between Mac and IPhone apps but the model code may well be similar/the same. So whats the best way to organise a project(s) so that the model code is/can be shared?
Copy/paste - just duplicate it and manually keep it in sync
Have 2 xcode projects point at the same workarea - one for Mac and one for IPhone and share the code.
Common library - presumably you can't do this (or can you)
Thanks for any tips.
There are a few ways to do this. The first thing you can do is is create a project that builds as a framework on Mac OS X. Since you cannot use frameworks on iPhone, you can make static library target that contains the same code files. That basically works, but the header paths will be different. If you want the header paths to be the the same (i.e. <Myframework/MyFramework.h>) you will need to modify the the install path of the static library headers so that they are copied into "$SDK_ROOT/usr/local/include/MyFramework", and make sure /usr/local/include is an included header search path. You will then need to install the library and headers into each SDK_ROOT.
I started out doing the above, but I found it to be a royal pain. So I ended up doing something that is a variant of #2. Basically, I get the header paths to be equivalent by making a directory named "Externals" in my iPhone project root, then a directory named with the appropriate name ("MyFramework") in the externals folder. That is the folder I copy I drag the framework files into.Findally I add the Externals folder as a system header path (which is admittedly sort of a gross hack). You need to manually add new files to the iPhone project, but I have found that to be less of a pain the installing static libs into my build root.
I'm not sure if the suggestion from the previous answer would work. If you look at my previous question, you'll see that I've failed to load a custom framework on the iPhone even though the framework works fine on Mac.
I would go with method 2.
You could develop your application in JavaScript, CSS, and HTML. You would use the WebView and UIWebView objects on the Mac and the iPhone respectively. You can do pretty much anything you want in the WebView objects, even make calls down to Objective-C.
The QuickConnectiPhone installer, found here https://sourceforge.net/projects/quickconnect/, installs QuickConnectMac and QuickConnectiPhone templates into Xcode.
This way you can quickly create an application in one environment and then migrate the view to the other. In fact the QuickConnect framework is highly modular.
If you don't want to develop in JavaScript the same modular framework is found on the Objective-C side of the templates installed.
It should make it much easier for you to do what you are attempting.