How do you create hybrid Xcode projects for Mac & iPhone?

前端 未结 4 749
旧巷少年郎
旧巷少年郎 2020-12-24 08:58

I\'m working on a project which shall contain two targets. One for building a Framework to use in Mac development and another to create a static library to use in iPhone dev

相关标签:
4条回答
  • 2020-12-24 09:40

    Probably the easiest (in terms of what you have to do) way of doing it is two projects (which you can wrap up as sub-projects of a dummy umbrella project if you like) which use the same sets of sources—one targeting Mac OS X, the other iPhone OS.

    Alternatively, can you not create two separate targets within the same project, and alter the “Base SDK” from the “Build” tab of the “Get Info” window for each? I don't have Xcode in front of me to check, but I think it'll let you do this.

    (Of course, with either approach, you can add a third target: a static library for the simulator, which will be useful when testing!)

    0 讨论(0)
  • 2020-12-24 09:49

    It's actually not that bad. Just create a second target of the appropriate type and then change the "Base SDK" build setting. Then make sure to add all the necessary files. If you want to build both at the same time, create an aggregate target. For a practical example see my project SSPromise.

    0 讨论(0)
  • 2020-12-24 09:57

    Just to let you know:

    I ended up having one project with different targets for the different platforms. But I didn't include the framework I depend on in the targets itself, but rather added them to the Other Linker Flags build settings:

    -framework Foundation -framework Security
    

    You can check it out in the project I did on github.

    0 讨论(0)
  • 2020-12-24 09:58

    Can't you use the PIMPL idiom? And/or have a common header for both but use different implementation file based on the target architecture or SDK?

    0 讨论(0)
提交回复
热议问题