How to share Swift classes across multiple targets of one Xcode workspace?

2.6k views Asked by At

I'm using Xcode 9 and Swift. I've got one workspace and one iOS project. Later I added a MacOS target (Cocoa App). When I try to reference a class from the MacOS target to the iOS target, the compiler says:

Use of unresolved identifier.

How do I get Xcode to allow me to share Swift classes from target to another?

1

There are 1 answers

1
Lance Kind On

This type of Xcode workspace organization is mentioned in Apple's documentation but doesn't describe how to allow the usage of implicit dependencies within Xcode.

Use Project Navigator to find the classes you wish to share with another target. Highlight the classes. Open the inspectors (icon in the top right corner of Xcode). On the right side a panel will appear. Change the "Target Membership" to include the other (in this case, MacOS) target.

After a rebuild it should work fine.