views:

735

answers:

4

My question is this: I have an application designed for iPhone and I decided to fork the code, in other words, I will develop two versions of the application at this initial phase, one for iPhone and the other for iPad.

My question is this: how do I fork the code? I would like to continue using one project for both versions but, obviously, I will have to write sections of code for the iPhone and other sections exclusively for iPad and will, of course, have many parts in common for both releases.

How do I do that without creating a mess on the code?

What are the best practices? Thanks for any help.

+1  A: 

You can configure your XCode project to use multiple targets, then you can assign some source code file to one target or to another or to both

scriba
two questions: 1)how do I do that assignment 2)what about parts of codes. Can I assign parts of codes to one target or the other? (compiled this IF ipad or that if iphone)... how is that done? thanks.
Digital Robot
+1  A: 

The problem with the multiple targets is that it might conflict with the distribution model.

From what I understand, iPad and iPhone applications will be distributed as a single binary. The application has decide whether to show the iPad or iPod user interface at runtime.

This means that if you do not want to have to separate apps on the store, 'Foo' & 'Foo iPad Edition', that you cannot use multiple targets and that you somehow will have to work with one code base.

I kind of hate this because there could be a lot of conditional stuff in the app. If iPad then do this, otherwise do that. If iPhone then show this view controller otherwise show the other. I don't htink this will lead to nice code.

So what I am currently thinking about is to do something in the middle: I will create basically two code bases and somewhere really early in the app I will decide to go a full iPad or iPhone code path.

St3fan
Apple docs do not say the application must be distributed as a single binary. On the contrary. It suggests that the decision is to be taken by the developer. I think more devices will come in the future, so things will get worst when a third device category is added.
Digital Robot
Yeah you are right. It is a developer choice.
St3fan
+1  A: 

I'm not an iPhone developer, but from what St3fan indicates (that it must be distributed as a single binary), these seems like a classic case for the factory pattern. Any thing that is different is implemented in two separate ways (with a common interface) and the factory spits a different implementation out based on if it's on an iPhone or iPad. Common code doesn't need to change so can remain as-is.

Darrell
+1  A: 

I reply to your points: 1) "how I do that assignment" you have to create a new Target from the Project Menu in my case I use two different targets for an iPhone game (a normal and a free (lite) version)

  so I created a second Target of Type Application
  this will add a Target to the Groups & Files panel
  and will create a new Info.plist file

  in the Group&File you can show more columns (by right clicking)
  on "Group&Files"), here you have to show the "Target Memebership column"
  for each file you can decide if it is part of a target by pressing the
  corresponding check box

2) "what about parts of codes" I don't know if the current Beta SDK used for developing iPad applications contains some #define you could test during compilation in every case you could set some dedicated #define at target level and test this to do some conditional compilation

you can find very detailed information about building applications with multiple targets in the dedcated apple documentation you can donwload it from the iPhone Dev Center you need to read this guide "Xcode Project Management Guide"

scriba
thanks!!!!!!!!!
Digital Robot