Cocoa框架开发:项目间共享
我目前正在开发一些类似的 Cocoa 桌面应用程序。为了在它们之间共享代码,我确定了一组可以在所有这些应用程序中通用的核心类和函数。我想将这个通用代码捆绑到一个框架中,我当前的所有应用程序(以及任何未来的应用程序)都可以链接到该框架。
现在,这是最困难的部分:我将一边开发这个框架,所以我需要每个桌面应用程序都引用它,但我希望能够在每个桌面应用程序中编辑框架源代码应用程序项目的一部分,并根据需要自动重建框架。
例如,假设我打开了 DesktopAppNumberOne 的 Xcode 项目,并且我决定需要更改我的框架类之一。我想:
- 打开并编辑该框架类的源文件,而不必在 Xcode 中打开框架项目。
- 在 DesktopAppNumberOne 上点击“构建”,首先查看重建的框架(因为其源之一已更改),然后查看 DesktopAppNumberOne 重建的部分内容(因为它链接的框架之一已更改)。
我可以看到如何仅使用一个应用程序和一个框架来执行此操作,但我无法弄清楚如何使用共享一个框架的多个应用程序来执行此操作。
有人用这种方法取得过成功吗?我是否可能以错误的方式处理这个问题?任何帮助将不胜感激。
I am currently developing a handful of similar Cocoa desktop apps. In an effort to share code between them, I have identified a set of core classes and functions that can be common across all of these applications. I would like to bundle this common code into a framework which all of my current applications (and any future ones) can link against.
Now, here's the hard part: I'm going to be developing this framework as I go, so I need each of my desktop apps to have a reference to it, but I want to be able to edit the framework source code from within each of the app projects and have the framework automatically rebuilt as required.
For example, let's say I have the Xcode project for DesktopAppNumberOne open, and I decide that one of my framework classes needs to be changed. I would like to:
- Open and edit the source file for that framework class without having to open the framework project in Xcode.
- Hit "build" on DesktopAppNumberOne, and see the framework rebuilt first (because one of its sources has changed), then see parts of DesktopAppNumberOne rebuilt (because one of the frameworks it links against has changed).
I can see how to do this with only one app and one framework, but I'm having trouble figuring out how to do it with multiple apps that share a single framework.
Has anyone had success with this approach? Am I perhaps going about this the wrong way? Any help would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为您的框架创建一个 XCode 项目。
在“组和”中文件面板>看到左上角的蓝色项目图标了吗?将其拖放到“组和组”中您喜欢的任何其他项目的文件面板。
因此,创建一个应用程序项目,然后从框架项目中拖入项目图标。
在您的应用目标上输入 CMD-i。在这里您可以设置对框架的依赖关系并链接到它。
几点
将多个应用程序链接到一个框架可能会带来压力。您需要将框架安装到 /Library/Frameworks 或同等版本中,或者捆绑到每个应用程序中。
出于开发目的,我发现为每个项目设置一个自定义的通用构建目录可以简化事情。我将每个项目设置为构建到 /Code/Build/Debug 中。这意味着调试构建的框架搜索路径可以是 $CONFIGURATION_BUILD_DIR。对于您的发布版本,您仍然需要在安装路径、rpath 等方面进行一些工作。痛苦!
XConfig 文件是您的朋友。开源 google mac 工具箱是如何使用它们的一个很好的例子。您可能至少需要 Project_debug.xconfig、Project_release.xconfig、Target_framework.xconfig、Target_application.xconfig 。
Make an XCode Project for you framework.
In the 'Groups & Files' Panel > See the Blue Project Icon at the very top left? Drag and drop that into the 'Groups & Files' Panel of any other project you like.
So, make an app project, and drag in the project icon from your framework project.
CMD-i on your app target. Here you set your dependency on the framework and Link against it.
A few points
Linking multiple apps to one framework can be stressfull. You will either need to install your framework into /Library/Frameworks or equivalent or bundle up into each app.
For development purposes, i find setting a custom, common build directory for each of the projects eases things. I set each project to build into /Code/Build/Debug. This means that framework search path for debug build can be $CONFIGURATION_BUILD_DIR. For your release builds you will still have some work todo with install paths, rpaths, etc. Pain in the Ass!
XConfig files are your friends. The Open source google mac toolbox stuff is a good example of how to use them. You will probably need at least a Project_debug.xconfig, Project_release.xconfig, Target_framework.xconfig, Target_application.xconfig.