I am writing a Swift script and I want to keep it clean. The way I would do this is by create multiple files and importing them. However, I can't figure out how to import another file into a Swift script. I am not using Xcode.
There's currently no way to import other swift files in a interpreted swift script. But you can concatenate all source files before executing them:
cat one.swift two.swift three.swift | swift -
If you're using the swift compiler, just add the files you want to compile together before the -o
argument:
swiftc one.swift two.swift three.swift -o combined
No need to import them, they are already in the same module.
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