K.Wu
K.Wu

Reputation: 3633

Is it possible to access classes in another target WITHOUT importing that target in Xcode?

In my test project, I created 2 targets like so:

Step 1:

enter image description here

Step 2:

enter image description here

Step 3:

enter image description here

Afterwards, I created TestClass1.swift in "TestTarget1" and TestClass2.swift in "TestTarget2":

// TestClass1
public TestClass1 {
    public static var randomNumber: Int {
        return Int.random(in: 1...100)
    }
}

And in TestClass2, I wish to access the random number generator in TestClass1 WITHOUT having to import target "TestTarget1", is this doable? e.g., by linking libraries, frameworks, etc.

You might wonder, "Why do you not want to import it?" It's very hard to explain, and I believe you don't really care, I just wonder if this is doable. Thank you!

Upvotes: 4

Views: 2347

Answers (1)

Rengers
Rengers

Reputation: 15238

For each source file in your project, you can choose the targets in which it is included. It is called "Target Membership" in the File Inspector in the right sidebar.

enter image description here

Upvotes: 7

Related Questions