Hi, I’m John Petitto, one of IBM’s Swift developers located at IBM’s Mobile Innovation Lab in Austin. We love Swift here and thought you would too so we are making our IBM Swift Sandbox available to developers on developerWorks.
The IBM Swift Sandbox is no longer available as of January 2018. The IBM Swift Sandbox was an interactive website that let users write Swift code and execute it in a server environment on top of Linux. With the maturity of server-side Swift and the proliferation of cloud computing, there are now more effective and dynamic ways to experiment with Swift on the server. For example, IBM’s App Service console will create and deploy a server-side Swift application in less than five minutes. Other useful tools, such as Kitura Init and IBM Cloud Developer Tools, quickly create and run a Kitura application in a local sandbox. Read the full deprecation announcement for Swift Sandbox and Package Catalog or explore our current server-side Swift resources.
We know you’re as excited as we are to start using this tool, so please bear with us during the initial launch of the sandbox. With that in mind, let’s get started!
To begin, let’s write a simple Swift program together. In the left window labeled source code, enter the following line of code:
New to Swift? Check out the official language guide.
Hit the blue run button located at the top to execute the program. If everything was entered correctly, “Hello Swift!” should appear under output in the results window.
If we edit the previous example and omit the closing parenthesis at the end of the line, an error should get flagged by the editor. Hover over the red marker that appears next to the line number to examine the error message. Error messages are also listed in the output.
Swift Meets Linux
We’ve provided a collection of sample programs for you to experiment with. Click Source Samples in the upper left corner to see the list of available sample programs. For instance, select filestat.swift and run the program. The output generated should be similar to what’s seen below:
/bin/bash is 1037464 bytes
If we try changing the value of
filename on line 12 from “/bin/bash” to “/tmp”, we should see a different number of bytes printed.
You may have noticed that this program is calling
stat from glibc (The GNU C Library). Since the sandbox runs on top of Linux, we can write Swift code that interacts directly with the system. Take a look at some of the other samples for more examples of using glibc.
With the movement of Swift to open source, we’re opening the doors on what we are working on at IBM with Swift. The IBM Swift Sandbox barely scratches the surface of what’s possible. To stay up to date with the open source efforts around Swift, head on over to Swift @ IBM.