Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to develop in Swift without Xcode IDE

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.

like image 394
FunTimeCoding Avatar asked Nov 01 '22 06:11

FunTimeCoding


1 Answers

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

like image 149
Diego Freniche Avatar answered Nov 09 '22 10:11

Diego Freniche