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

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.

Related

Multiple Target Devices for a Single AS3 Project

I am porting an existing project from Flash Pro to Flash Builder.
The code is almost completely portable between Web/Android/Projector/AIR, and I simply change a few constants for each target device before hitting publish...
However- in Flash Builder, it asks me when creating a project whether it will be mobile or web.
What's the best-practices way to target multiple devices from a single project in Flash Builder?
OR, in Flash Builder, must they each be their own project? If they must each be their own project- is there a multi-project organization method which works well, keeping in mind that in this context each project is really just a different build of the almost-identical codebase (On one foot- I thought of having a "common" project which would hold most classes, and then each build-project instantiates a Main class from there...)?
Thanks!
You can create a mobile project with one codebase and select multiple devices (android, ios, blackberry playbook). If you also want a web version, you should be able to specify that codebase in the build path for your web version. You do that by going to Properties --> Actionscript Build Path. Click Source Path and then browse to the folder that contains those files. So yes, you can create a different Main.as, if you need to, for each project. Although in Actionscript the entrypoint class generally has the same name as the Project itself.
You'll then be able to modify one set of files, but the modifications will apply both to the original project and to any project which references those files in this way.

iPhone Project Dependency Management

Has anyone had any success in finding a reliable, generalised solution for managing dependencies for iPhone projects? I'm looking to split my iPhone applications up into reusable components and then pull them into projects that require them. I guess I'm looking for a Maven-esque workflow but for Xcode/iPhone projects. I've tried a number of things so far such as:
I've created a Maven plugin for iPhone applications which automates the building and signing of the applications but I constantly feel like I'm fighting against Maven to get this to work and it is altogether pretty messy. I'd rather not use this unless there are no other options.
I have also tried using static libraries to package the code up to re use but the problem with this is that I'd also like to include reusable XIBs and images in my projects and these cannot be included in the static library for redistribution. They are great for code but I'd like to have one system that does everything rather than different dependency management systems for different types of dependency.
At the moment I've settled on using the version control system to do my dependencies for me. In this case I'm using SVN externals to load the dependencies into the workspace when I checkout the project.
Does anyone have any ideas as to what I could do?
Update
I'm now using CocoaPods to perform this task.
The way I've done it in the past is as follows:
Static Library for shared code
Bundle for Images / Data Files / Etc (Non Code)
By doing this, you only ever have to worry about updating the project that manages your static library / bundle and not the applications that use them.
The key thing to creating a bundle, is that Bundles are not listed under iOS when adding a new target to a project. Instead they are listed under Mac OS X. Don't worry, it works great.
Once you've created your Bundle and Static Library targets, you'll need to get those into your application:
Add the Static Library under Link Binary With Libraries (Xcode 4)
Add the Bundle under Copy Bundle Resources (Xcode 4)
The final thing to keep in mind is that when you want to load resources from the newly created bundle you need to do something like the following if you were going to load an image:
UIImage *myImage = [UIImage imageNamed:#"YourBundle.bundle/MyImage.png"];
With Static Libraries, you can distribute the XIB's/Images/Strings in a Bundle Folder which can be imported easily. It is the easiest approach I've found for distributing dependencies short of distributing the actual Code/Xcode Project

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.

Can an XCode static library require linkage with a dynamic library?

I have created a static library in XCode that requires several dynamic libraries (e.g. libsqlite3.0.dylib). I can create an application that is dependent upon my static library using cross-project references in XCode, but it seems that I have to manually add all of the required dynamic libraries to each of my application projects to get them to link.
Is there any way to configure a static library project in XCode so that dependent applications will automatically link against whatever dynamic libraries it requires?
I tried adding the dynamic libraries to the list of Frameworks in my static library project, but this seemed to have no effect.
Yes -- you will need to add the libraries to the applications. A static library -- a .a -- is just an archive of .o files with a minimal bit of internal symbol resolution. The full symbol resolution doesn't happen until you link it into an application (or framework).
(Are you using sqlite3 directly? If so, why not use Core Data? There are reasons, but not nearly as often as people thing...)

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

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