Darren Findlay
Darren Findlay

Reputation: 2563

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. 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.

Upvotes: 1

Views: 1644

Answers (3)

Travis M.
Travis M.

Reputation: 11257

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.

Upvotes: 0

Midhun MP
Midhun MP

Reputation: 107231

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.

Upvotes: 2

Vitalii Gozhenko
Vitalii Gozhenko

Reputation: 9354

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

Upvotes: 3

Related Questions