简体   繁体   English

如何将独立的Xcode项目作为模块导入另一个项目?

[英]How to import standalone Xcode Project as a module to another project?

Both projects use same frameworks. 两个项目使用相同的框架。 both have appdelegates. 两者都有代表。 Successfully added both projects in workspace. 成功将两个项目添加到工作区中。 but can not access each others controllers. 但不能互相访问控制器。 making a static library of one project did not help. 为一个项目创建静态库没有帮助。 making a framework of one project?? 使一个项目的框架? which way to go? 往哪走?

Because you're talking about making a static library, I think your project is an OC project. 因为您正在谈论制作静态库,所以我认为您的项目是OC项目。 So here's the thing, if you're going to merge these two apps , you should first take out the contents that can't be duplicated, like AppDelegate and some other app settings. 因此,如果要合并这两个应用程序,则应首先取出不可复制的内容,例如AppDelegate和其他一些应用程序设置。

You said you put two projects into one workspace but you can't access to one project's view controllers from another. 您说过将两个项目放入一个工作区,但无法从另一个访问一个项目的视图控制器。 That's because you did not import the header in a right way. 那是因为您没有以正确的方式导入标头。

For example, each project has its own header search path, which can be set at your xcodeproj-Build Settings->search header search path. 例如,每个项目都有自己的标题搜索路径,可以在xcodeproj-Build Settings-> search header搜索路径中设置该标题搜索路径。 By default, the current path(".") of one xcodeproj's header search path is at where your xcodeproj placed. 默认情况下,一个xcodeproj标头搜索路径的当前路径(“。”)位于您的xcodeproj所在的位置。 And Xcode search all of the headers in that folder recursively. Xcode递归搜索该文件夹中的所有标题。

If you want to access app B's header from app A. Assumed that you had a view controller in your app A's root folder. 如果要从应用程序A访问应用程序B的标头。假定您在应用程序A的根文件夹中有一个视图控制器。 To Access app B's header, your import may seem like so: 要访问应用B的标题,您的导入可能看起来像这样:
#import "../app B/somekindofVC.h"
If you just want to import "somekindofVC.h", you can add "../app B" as a header search path in Build Settings, and select the 'recursive' option if necessary. 如果只想导入“ somekindofVC.h”,则可以在“构建设置”中添加“ ../app B”作为标题搜索路径,并在必要时选择“递归”选项。

That's how your xcodeproj can find another's headers. 这就是您的xcodeproj可以找到其他人的标头的方式。

There is one more important thing should be done is that you should add app B's shared code into compile source. 还有一件重要的事情是您应该将应用程序B的共享代码添加到编译源中。 Since your app A could know a class of app B through header, the compiler doesn't know what is the implementation of app B's classes. 由于您的应用A通过标头可以知道应用B的类,因此编译器不知道应用B的类的实现是什么。 So before you run your project, remember to add '.m' files you need in Build Phases->Compile Sources. 因此,在运行项目之前,请记住在构建阶段->编译源代码中添加所需的'.m'文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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