Single Xcode project for iOS and Mac OS X

In Xcode 3.2.4, it’s trivial to create same project for iOS and Mac OS X. Just add a new target into your existing project; if your project is for OS X, then create a new Cocoa Touch Application target. If your project is for iPhone, obviously, craete a new Cocoa Application target. Then do a Get Info on your new target, and choose the appropriate Base SDK. For simplicity, let’s presume you’re adding an OS X target to an iPhone project.

However, after doing this, you’ll quite probably find that despite the choice of Base SDK in your target (you used Get Info on it, didn’t you?), Xcode has locked the target SDK onto whatever your project originally used. That is, now you’ll find it locked onto iPhone, despite switching to the OS X target using the Overview dropdown (in the top left of your Xcode project).

So how do you actually switched the now-locked SDK? Quite simple. Hold the option key while clicking in the Overview box. Instead of only two-entries device list (if you have an iPhone target selected), and then Active Configuration, Active Target, Active Executable and Active Architecture, by holding the option key while clicking on Overview you’ll also find the Active SDKs list. By switching it to the appropriate OS, you’ll be able to compile the application.

Of course, now comes the hard part: actually porting the code to the new platform.
E49PEQSG669E

6 thoughts on “Single Xcode project for iOS and Mac OS X

  1. Despoke

    Hello,

    Thanks for this trick! I’m new to xcode and I spent the last 3h trying to figure out why my 2 static libs (one for ios, the other for mac) would not compile when in the same xcode project! How can you know this trick with option+Overview???

    Ta,
    Despoke

    Reply
  2. Samuel

    This is awesome, thanks for the info. In some older versions of Xcode, it used to just work, and then I suddenly found after upgrading to the latest Xcode my projects wouldn’t compile properly. Thanks!

    Reply
  3. Samuel

    This is awesome, thanks for the info. In some older versions of Xcode, it used to just work, and then I suddenly found after upgrading to the latest Xcode my projects wouldn’t compile properly. I couldn’t figure out how to select the active SDK… but now I know! Thanks :p

    Reply
  4. Konstantin

    Hello Ivan! Thank you for this trick – it’s works!
    Interesting – where we could find this magic button in documentation?

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

 

What is 3 + 11 ?
Please leave these two fields as-is:
IMPORTANT! To be able to proceed, you need to solve the following simple math (so we know that you are a human) :-)