How do I have an iOS App and OS X App in the same project?

故事扮演 提交于 2019-12-05 00:11:14

问题


I've seen this question about whether or not it's possible to make an iOS App and a Mac OS X App in the same project, while I was trying to ask this. I'm not asking about whether or not it's possible. I had to delete and re-install Xcode (because I wanted to update and my MacBook Air's SSD is really low on space), and I came across this screenshot.

Besides the absolutely beautiful 3D scenery on the right side, I looked at the project structure on the left. They have OS X files in one group and iOS files in another.

How would I be able to make my project this organized? As in, how would I go about making a project where I can simply have OS X files and iOS files be simply two different groups of files in the same project, and work on each app almost synchronously?


回答1:


Figure out how to do this, leave some screenshots in case it may help others.

I did the OSX App first, put the common code apart, then click file menu to create the target as iOS App.

Use the common code to build iOS App, Now you can already see the target has both OSX and iOS, remember to add the needed files in the Compile Sources and Resources.

Now you can both choose whether to run on iOS or OSX. Done!




回答2:


The answer seems quite straight-forward. Xcode allows you to create groups in order to organize files. Each source file can belong to one-or-more targets, so it's just a case of putting all common, iOS-specific and OSX-specific files in their own groups and setting their targets.

- Source
    - Common
        - File1.m       Target: iOS and OSX
        ...
    - iOS
        - File2.m       Target: iOS
        ...
    - OSX
        - File3.m       Target: OSX
        ...



回答3:


You can add a Mac OS X target in the same project~Choose the file which should add to iOS target and which should add to mac os x target



来源:https://stackoverflow.com/questions/33953155/how-do-i-have-an-ios-app-and-os-x-app-in-the-same-project

标签