简体   繁体   English

一个Xcode项目使用另一个项目而不创建静态库

[英]One Xcode project using another without making a static library

I just banged my head for a while and figured out a solution, but I want to make sure that I'm doing things right and that I actually know what I'm doing (I'm pretty sure I never know what I'm doing :) 我只是想了一下解决办法,但我想确保自己做的正确,而且我确实知道自己在做什么(我很确定自己永远不会知道自己在做什么。在做:)

I have two projects that I've been working on, each offering different functionality. 我有两个正在从事的项目,每个项目提供不同的功能。 I want one project (A) to be able to use the functionality of the other (B). 我希望一个项目(A)能够使用另一个项目(B)的功能。 I tried going about it by creating a workspace and putting both projects into it, but I couldn't "see" project B's files from project A (autocomplete after #import did work, but it gave a compiler error). 我尝试通过创建工作区并将两个项目放入其中来解决该问题,但是我无法从项目A中“看到”项目B的文件(#import起作用后自动完成,但出现了编译器错误)。 So I tried adding it as a "sub-project" and found the same. 因此,我尝试将其添加为“子项目”,并发现了相同的结果。 I figured this would be easy, but guess not. 我以为这很容易,但是猜不到。

What I ended up doing was creating a new project (C) as a "Cocoa Touch Static Library" project, and put my files from Project B into it. 我最终要做的是创建一个新项目(C)作为“ Cocoa Touch Static Library”项目,并将我的文件从Project B放入其中。 I built it. 我建好了

I then went back to project A and added project C into it as a sub-project. 然后,我回到项目A,并将项目C作为子项目添加到其中。

Then I added the path on the filesystem of project C into the User Header Search Paths setting under Build Settings of project A. 然后,将项目C的文件系统上的路径添加到项目A的“构建设置”下的“用户标题搜索路径”设置中。

Then I added the .a file from Project C into the Link Binary with Libraries section of Project A. 然后,将项目C中的.a文件添加到项目A的“链接库二进制文件”部分。

Then it worked. 然后它起作用了。

But honestly I have no idea what the meaning of a static library is. 但老实说,我不知道静态库的含义是什么。

Is all this necessary? 这一切必要吗? Or is there an easier way to just integrate two projects (without me having to copy the files from one project to another)? 还是有一种更简单的方法来仅集成两个项目(而无需我将文件从一个项目复制到另一个项目)?

Thanks in advance! 提前致谢!

Jon 乔恩

You were on the right track with workspaces. 您在使用工作区的正确轨道上。 What I do is have three projects in the workspace. 我要做的是在工作区中有三个项目。 One with no targets just to hold the generic classes. 一个没有目标的类仅用于容纳泛型类。 A second for my iOS target Project. 我的iOS目标项目需要一秒钟。 And a third for mac. 还有Mac的三分之一。 Keep the original files in the one with no target, then drag the files to the other two projects that creates references, so when you edit one it changes all three. 将原始文件保留在没有目标的文件中,然后将文件拖到创建引用的其他两个项目中,因此在编辑其中一个文件时,所有三个文件都会更改。

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

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