简体   繁体   English

在Xcode项目之间共享类

[英]Sharing classes between Xcode projects

A while ago I developed an iOS application using Xcode that and created a bunch of classes that work together to communicate with a RESTful API. 不久前,我使用Xcode开发了一个iOS应用程序,并创建了一堆可以与RESTful API通信的类。 Now I'm creating a second app, totally separate but communicates with the same API. 现在,我要创建另一个应用程序,该应用程序完全独立,但使用相同的API进行通信。 I want to reuse these classes, what is the best way to approach this? 我想重用这些类,最好的方法是什么? Should I be do the via some Version control system? 我应该通过某个版本控制系统来执行吗? Or should I use an Xcode workspace? 还是应该使用Xcode工作区?

Thanks in advance for any help. 在此先感谢您的帮助。

我更喜欢为选定的文件创建单独的Git存储库,并将该存储库作为子模块嵌入到两个项目(新旧项目)中

In similar situation I done it using XCode Workspace and Static Library. 在类似的情况下,我使用XCode Workspace和Static Library做到了。

I added the common classes to a Static Library project and added that to the XCode Workspace. 我将公共类添加到静态库项目中,并将其添加到XCode工作区中。 In my second project I added that Static Library Project. 在第二个项目中,我添加了“静态库项目”。

I have two options there: 我有两个选择:

  1. Adding that Static Library project to the new project workspace 将该静态库项目添加到新项目工作区
  2. Adding the static library (.a) project to the new project 将静态库(.a)项目添加到新项目

I chose the first option because, I can add the other common files to that Static Library and also modify the existing files if needed. 之所以选择第一个选项,是因为我可以将其他通用文件添加到该静态库中,还可以根据需要修改现有文件。

As Midhun and yourself mentioned, the best way to do it us by making a workspace and adding your projects to that. 正如Midhun和您自己所提到的那样,最好的方法是创建一个工作区并向其中添加项目。

Your shared code can go into a new project that's basically empty and dragged/linked from there into any projects in your workspace. 您的共享代码可以进入一个基本上为空的新项目,然后从那里拖动/链接到您工作区中的任何项目中。

Changes made to that code from any project will also update the shared code base, which I think is what your ultimate goal was. 从任何项目对该代码进行的更改也将更新共享代码库,我认为这是您的最终目标。

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

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