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

1

6

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?

Lexicographer answered 5/10, 2018 at 21:5 Comment(0)
L
7

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.

Lexicographer answered 5/10, 2018 at 21:11 Comment(1)
This can be problematic though if you try to import two targets that share the classes: "Ambiguous use of... "French

© 2022 - 2024 — McMap. All rights reserved.