views:

121

answers:

2

I have an iPhone app that I would like to port over to the iPad, but I would like to have as little duplication as possible.

How do people usually go about doing this?

In xcode can you have different targets for iPhone and iPad and perhaps do some pre-processor checks? Or is it best to simply have two separate projects altogether?

Note, Im NOT talking about running the iPhone app on the iPad, I mean creating a native 3.2 app...

EDIT

So it looks like creating a universal application is the way to go:

http://developer.apple.com/iphone/library/documentation/General/Conceptual/iPadProgrammingGuide/StartingYourProject/StartingYourProject.html#//apple_ref/doc/uid/TP40009370-CH9-SW8

But what I still dont understand is how to select different NIB files based on your current deployment???

Thanks a lot

+2  A: 

For minimal duplication, you can use one project, with 2 sets of .nib files, but one set of source code files which include run-time checks for the UIUserInterfaceIdiom differences.

If you want two (or more) apps instead of a Universal app, just create two targets containing only the appropriate .nib files, and #ifdef the run-time check results using a Preprocessor Macro define in each target's Build Settings to force iPhone or iPad idiom only.

hotpaw2
yep thats what Im looking for, what exactly is the UIUserInterfaceIdiom? I cant find much on it?
Mark
It's a device property that tells an app about the device on which it's running, documented in the UIDevice Class Reference on developer.apple.com
hotpaw2
ah, that one, whops, so now how do I chose, which NIB to load based on the device?
Mark
Here's the process I used:1. Update your target to be a single universal application2. Make note of the new XIB file XXX-iPad.xib that xcode creates for you 3. Create new XIB files that correspond to your iPad application (you can create new XIB files that point to your existing UIViewController's, just add a single "View XIB", change its class to your existing view controller)4. Inside that XIB file, change the normal XIB files that load to point to the new XIB files you made in step 3 5. Connect up your IBOutlet's like you would normally in your new XIB
Mark
+1  A: 

The latest (3.2.3) Xcode auto-generates a Universal project which is a great starting point to see how to target iPad and iPhone in one Xcode project.

File > New Project > Window-based Application > Product : Universal

ohho