joseph.hainline joseph.hainline - 4 years ago 3280
Swift Question

How do I import a Swift file from another Swift file?

I simply want to include my Swift class from another file, like its test


import Foundation

class PrimeNumberModel {


import XCTest
import PrimeNumberModel // gives me "No such module 'PrimeNumberModel'"

class PrimeNumberModelTests: XCTestCase {
let testObject = PrimeNumberModel() // "Use of unresolved identifier 'PrimeNumberModel'"

Both swift files are in the same directory.

Answer Source

I had the same problem, also in my XCTestCase files, but not in the normal project files.

To get rid of the

Use of unresolved identifier 'PrimeNumberModel'

i needed to import the base module in the test file. So in my case my target is called 'myproject' I added import myproject and the class was recognised.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download