xcode 为 Mac OS X 和 iOS 开发

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6511536/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 21:22:14  来源:igfitidea点击:

Developing for both Mac OS X and iOS

iosxcodecocoamacos

提问by Colin

I'm working on a game that I'd like to ultimately be available for Mac OS X and iOS. What's the best way to do this? Should I (1) focus on one OS first and get a polished version 1.0, then port to the other OS, or (2) should I try to develop for both simultaneously from the start?

我正在开发一款我希望最终可用于 Mac OS X 和 iOS 的游戏。做到这一点的最佳方法是什么?我应该 (1) 首先专注于一个操作系统并获得一个完善的 1.0 版,然后移植到另一个操作系统,还是 (2) 我应该从一开始就尝试同时为这两个操作系统进行开发?

If (1), which OS should I target first, i.e. which porting direction is the easiest?

如果 (1),我应该首先针对哪个操作系统,即哪个移植方向最简单?

If (2), do I need a separate project in XCode for each OS? If so, how do I maintain just one copy of the platform agnostic code that I share between both projects?

如果 (2),我是否需要在 XCode 中为每个操作系统创建一个单独的项目?如果是这样,我如何仅维护我在两个项目之间共享的平台不可知代码的一份副本?

回答by Eiko

I usually code in parallel, sometimes starting on Mac, sometimes on iOS. Most of the core functions (i.e. non-GUI) is virtually the same on both platforms, but sometimes someof the functionality is missing on one part. Then I try to start off with the poorer platform so that the code will run on both.

我通常并行编码,有时在 Mac 上开始,有时在 iOS 上。大多数核心功能(即非 GUI)在两个平台上几乎相同,但有时某些功能在某一部分缺失。然后我尝试从较差的平台开始,以便代码可以在两个平台上运行。

Working in parallel gives another benefit: you need to think about good abstraction or you will get annoyed of duplicated code rather quickly. Multiple targets really help with good structure.

并行工作还有另一个好处:你需要考虑好的抽象,否则你很快就会对重复的代码感到恼火。多个目标确实有助于良好的结构。

As for the multiple targets - yes, in theory this works in Xcode. It was a real pain (with losing references over and over) as soon as I put my "core code" in static libs and keeping everything updating automatically.

至于多个目标 - 是的,理论上这适用于 Xcode。一旦我将我的“核心代码”放在静态库中并保持所有内容自动更新,这真的很痛苦(一遍又一遍地丢失引用)。

Mysetup is as follows:

我的设置如下:

MainWorkspace
   CoreFunctionsMacLibProject
   CoreFunctionsIOSLibProject
   TheApplicationMacProject
   TheApplicationIOSProject

The shared code for the core part is in a shared folder, updates are easy given everything is in the same workspace. It would work easily without the separate libraries, I just happen to use them in different projects/workspaces as well.

核心部分的共享代码位于共享文件夹中,鉴于所有内容都在同一工作区中,因此更新很容易。如果没有单独的库,它会很容易工作,我也碰巧在不同的项目/工作区中使用它们。

So far everything goes smooth. Talking about 2-4 libs and several app projects. Just my experience, though. Workspaces make this approach pretty flexible, as you might put a project in more than one workspace.

到目前为止,一切都很顺利。谈论 2-4 个库和几个应用程序项目。只是我的经验,虽然。工作区使这种方法非常灵活,因为您可以将一个项目放在多个工作区中。