Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to port a Cocoa app to iPhone-OS?

I am about to create a Cocoa app and I want to ensure that one day I can easily port it to the iPad or even the iPhone. How can I plan for this in advance?

I know I will have to redo all NIBs and probably design a different workflow.

But what about the code? Just replacing every NSsomething with UIsomething won't cut it, right? Any tips on how to make sure now that I won't shoot myself in the foot later?

Thank you!

(The iPad-SDK is under NDA. For the sake of this question just assume i asked about the iPhone, OK? Or think iPhone with a bigger screen.)

like image 982
Ron Avatar asked Jan 31 '26 00:01

Ron


1 Answers

Make sure you strictly uphold the Model-View-Controller separation in your app. The model, especially, should never depend on any controller or view.

In porting to the iPhone/iPod touch/iPad, you'll need to replace most or all of the controllers and all of the NSViews and NSCells. You should be able to keep your CALayer subclasses, if you have any. You may be able to reuse one or two controllers with conditional compilation, if most of a controller will work on both but some parts only work on the Mac or work on both but with completely different APIs. And you should be able to keep the entire model unchanged.

There are probably some more specific pitfalls that an iPhone developer can warn you about, but this is the general rule that holds for any transition from one environment to another. (An example of another environment transition would be making one or more command-line tool equivalents or complements to your app, like xcodebuild, packagemaker, or ibtool.)

Also, look at the Introduction to the Foundation framework reference for figures showing which Foundation classes are Mac- and iPhone-only.

like image 101
Peter Hosey Avatar answered Feb 02 '26 13:02

Peter Hosey