简体   繁体   中英

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

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?

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!

在此输入图像描述

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
        ...

您可以在同一个项目中添加Mac OS X目标〜选择应添加到iOS目标的文件以及应添加到mac os x target的文件

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM