Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 772
Lance Kind Avatar asked Oct 05 '18 21:10

Lance Kind


1 Answers

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.

like image 99
Lance Kind Avatar answered Oct 19 '22 10:10

Lance Kind