在 iOS 和 Mac OS 应用程序之间共享业务逻辑代码
我有一个 iOS 应用程序,正在考虑将其移植到 Mac OS 上运行并通过 Mac App Store 进行销售。但是,我希望业务逻辑能够尽可能多地重用代码,这样,如果我修复一个产品中的错误,我就不必为另一产品重新编码所有内容。最好的方法是什么?对于通用的 iPad/iPhone 应用程序,只有两个目标,但显然对于 Mac OS 应用程序,整个结构是不同的,并且它使用完全不同的 SDK。有什么建议吗?谢谢你!
I have an iOS application which I am considering porting to also run on Mac OS and sell via the Mac App Store. However I would like to have as much code re-use as possible for the business logic, so that if I fix a bug in one product I won't have to re-code everything for the other product. What is the best way to do this? With a universal iPad/iPhone app, there are simply two targets, but obviously for a Mac OS app the whole structure is different and it uses an entirely different SDK. Any suggestions? Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
做到这一点的最佳方法是将 Cocoa 应用程序目标添加到您的项目中。转到 Project>New Target,然后从 Mac OS X 部分选择 Cocoa>Application。然后,选择新目标后,单击复选框以包含共享文件。
The best way to do this would be to add a Cocoa application target to your project. Go to Project>New Target and choose Cocoa>Application from the Mac OS X section. Then, with your new target selected, click the checkboxes to include the shared files.
您可以做的另一件事就是简单地将一个项目中的文件添加为另一个项目的引用。只需将它们从源项目(实际文件所在的位置)拖到另一个项目中即可。该对话框将询问您是否要复制文件。选择否。这将使第二个项目指向第一个项目中的文件。编辑会进入这两个项目。
不过要小心这一点,因为 iOS 和 MacOS 中的 API 之间存在一些差异,即使它们的调用方式相同。
Another thing you can do is simply add the files from one project as references to the other one. Simply drag them from the source project (where the actual files reside) into the other project. The dialog will ask you whether you want to copy the files. Choose no. This will make the second project point to the files in the first project. Edits go into both projects.
Be careful with this, though, as there are a few differences between APIs in iOS and MacOS, even if they are called the same.