Sharing classes between Xcode projects

ぃ、小莉子 提交于 2021-01-28 19:43:44

问题


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. Now I'm creating a second app, totally separate but communicates with the same 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?

Thanks in advance for any help.


回答1:


In similar situation I done it using XCode Workspace and Static Library.

I added the common classes to a Static Library project and added that to the XCode Workspace. 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

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.




回答2:


I prefer to create separate Git repository for selected files, and embed this repository as submodule in both projects (old and new one)




回答3:


As Midhun and yourself mentioned, the best way to do it us by making a workspace and adding your projects to that.

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.



来源:https://stackoverflow.com/questions/27434163/sharing-classes-between-xcode-projects

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!