Setting up XCode 4 workspace to build a library for both Mac and iOS

I am trying to build a couple of apps within an XCode workspace: One app will be an iOS app and another will be a Mac OS X app. I'd like to have a certain set of classes that get included in both versions of the app. I'm struggling to figure out what kind of project structure would best support some code that is shared, some that is specific to the iOS app, and some that is specific to the Mac app. Is there a best practice for doing this kind of thing in XCode in general or XCode 4 specifically?

Should I be creating a library project for the shared code and creating 2 different targets for the iOS and Mac OS X builds of the library? The build-in project templates seem to want me to pick either a Mac OS X library or an iOS library, and I'm not sure if it's easy to make a project based on one of those templates work for both targets.

Should I instead be creating different projects for the iOS library, the Mac OS X library, the iOS app, and the Max OS X app? In this case, how can I easily have the library code shared between the iOS library and Mac OS X library projects?


You won't be able to make a library in the sense of a shared library file that you can link against, because code for iOS is compiled for ARM processors whereas code for OS X is compiled for Intel processors (different machine code instruction sets).

You should probably just make the code that will be shared in to a separate project and then add the project itself as a dependency.

And here's another SO question that's similar to yours about porting from one platform to the other

链接地址: http://www.djcxy.com/p/53512.html

上一篇: 如果只选择一行,则排名前1位更快

下一篇: 设置XCode 4工作区为Mac和iOS构建库