Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I import other Swift files into a Swift script? [duplicate]

Tags:

import

swift

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.

like image 366
Caleb Kleveter Avatar asked Mar 28 '16 15:03

Caleb Kleveter


1 Answers

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.

like image 75
redent84 Avatar answered Oct 21 '22 19:10

redent84