How to create my own "shell" command line program in Mac OS X
The easiest way to do this is probably the following:
- open a terminal window and navigate to the directory of your choice
Create an empty swift file by entering the terminal command
touch myFirstProgram.swift
Make this file executable by entering the terminal command
chmod +x myFirstProgram.swift
Open this directory in finder by entering the terminal command
open .
Double-click on myFirstProgram.swift to open the empty file in Xcode. Then, inside Xcode, write the following lines into your first swift program. The first line starts the swift interpreter, anything after that is simple swift code.
#!/usr/bin/env xcrun swiftprintln("Hello world.")
After saving your program, you can start this by entering the terminal command
./myFirstProgram.swift
done.
Once you have understood these steps, you can go out and explore freely. I found, for example, an excellent first tutorial athttp://practicalswift.com/2014/06/07/swift-scripts-how-to-write-small-command-line-scripts-in-swift/. The only outdated information I found there was that the first line of the swift program should be as I detailed in point 5 (without a "-i" at the end of the line).
Have fun!