Skip to content

Instantly share code, notes, and snippets.

Created June 3, 2014 14:34
Show Gist options
  • Star 25 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/60ba68bd9f185f1f644c to your computer and use it in GitHub Desktop.
Save anonymous/60ba68bd9f185f1f644c to your computer and use it in GitHub Desktop.

How to use swift in your terminal

setup

First, install Xcode 6 beta.

And run it.

sudo xcode-select -switch /Applications/Xcode6-Beta.app/Contents/Developer

By xcrun swift, repl will start.

$ xcrun swift
Welcome to Swift!  Type :help for assistance.
  1> var x = 3
x: Int = 3

How to compile

Write swift code.

foo.swift

func x() -> Int {
	return 3
}

println("hello")

compile

$ xcrun swift foo.swift
$ ./foo
hello

It works! yey!

@colinta
Copy link

colinta commented Jun 4, 2014

println("\(C_ARGC)")
var index : Int
for index in 0..C_ARGC {
  println("\(index): \(C_ARGV[index])")
}
> swift swift-test.swift
swift-test.swift:4:31: error: 'Int32' is not convertible to 'Int'
  println("\(index): \(C_ARGV[index])")
                              ^

😫

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment