I want to put together a runnable script and a class to include from a separate module.
If I put the class into the script like this, it works.
#!/usr/bin/env swift
class HelloWorld {
func greet() {
print("Hello World")
}
}
var h = HelloWorld()
h.greet()
However, when I put the HelloWorld class into a HelloWorld.swift module, I have found no solution to get it to work.
You just need to do:
$ swift HelloWorld.swift
And you HelloWorld.swift
:
class HelloWorld {
func greet() {
print("Hello World")
}
}
var h = HelloWorld()
h.greet()
Important: as of Swift 1.2 you can only have one big scripting file. Reference
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