command line - How to Import modules without an Xcode project in Swift -


i using command line create swift files , using "swift" command in order run 1 of them. 1 file able access functions file. if c use #include macro , specify file is. swift's import statement doesn't seem allow that. there should way , know how it.

for example:

if have file function in , make file uses function. how allow use it?

// file1.swift import foundation  func sayhello() -> string {     return "hello" }  // file2.swift import file1  // <-- trying import file1 doesn't work  println(sayhello()) 

once files have been made write "swift file2.swift" in terminal. tells me..

error: no such module 'file1.swift' 

clearly swift compiler looking module. how make file1 module? i've seen solutions take place in xcode. i'm looking in command line.

// file1.swift func sayhello() -> string {     return "hello" }  // main.swift println(sayhello()) 

and terminal:

$ swiftc file1.swift main.swift  $ ./main  hello 

Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

python - NameError: name 'subprocess' is not defined -