How to import module like "UIKit" when using "swiftc" command to compile swift file?

Viewed 1424

I create a swift file (test.swift):

import UIKit

func test() {
    let view = UIView()
    print(view)
}

Then run the command swiftc test.swift in terminal. It outputs

error: no such module 'UIKit'

How to import the 'UIKit' module?

1 Answers

You need to link sdk and specify what target you building for:

swiftc input.swift 
    -o output.o 
    -sdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS12.0.sdk 
    -target arm64-apple-ios12.0
Related