问题
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:
- Adding that Static Library project to the new project workspace
- 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