protasm
protasm

Reputation: 1297

Create Framework / Library / Module of Swift Objects in Xcode

I am a (very) novice iOS/Swift programmer with a basic question about moving reusable software objects to their own ... something.

I am developing three iPhone apps that present information from three distinct data sets. Those data sets contain unique information but are structurally similar. As such, the apps share some Swift classes that are identical, specifically the classes that model the data. As I continually refactor the code, I find that when I tweak a class in one app's project, I have to remember to go to the other two projects and make the same tweaks to the same classes for those apps. It's getting to be a big headache.

What I would like to do is have one class definition in its own ... something that I can share, link, import, or attach to/from each app's project. From my online research, I suspect that the ... something is a library? or maybe it's a framework? or a module? I have found all three terms are used, but I am not sure how they relate to each other.

Given that all of the software I am writing is in Swift, does Xcode support what I am trying to do? Thank you!

Upvotes: 0

Views: 550

Answers (1)

timbo
timbo

Reputation: 14334

It seems you have the issue of needing the same Swift class in multiple projects. You could build a Framework (aka Module) for this class then copy it in to each project. This is probably the formally correct approach but it is a bit of overkill for just a single class.

Instead, you could just make the file in the Navigator panel a reference in each project to the one actual file.

You could also make a Workspace and then put each project into the workspace and just have the file at the top level (but this may introduce some build complexity).

Upvotes: 1

Related Questions