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?
If you've installed the latest version of Xcode you should have a swift command available in your terminal, which launches a Swift REPL 1. You can run the Swift REPL from the command line and enter Swift code directly into it. Whenever you enter valid Swift code in the REPL, it will immediately compile and run it.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With