Add Swift 2.0 as a language!


#1

Now that swift is open source please add it as an available language I believe this would be in great demand and Cloud 9 YOU WILL MAKE A LOT OF MONEY OFF OF THIS. In the words of a wise actor DO IT, JUST DO IT.

p.s. sorry for the caps, but please it would be smart.

pls.


#2

Just searched about it, seems cool!
You can create ios apps now with coding text only? thats amazing :stuck_out_tongue_closed_eyes:

EDIT: You still need Xcode to make apps. yuck


#3

Indeed, this would be an awesome feature but Apple locks this down so this would be tough. You’d need to be developing on a Mac (as far as I know) so the only way to do this would be to create an SSH workspace with a Mac machine and then program on that.


#4

I understand the difficulty of using c9 to build an iOS, macOS app. But there is a lot going on with “server-side” Swift. I’m working on a tutorial series and it would be cool to use c9 for it, so I can avoid a whole bunch of setup issues.

One can now use Swift to build on Linux without xCode :

  • Web Applications with one of the many frameworks popping up such as vapor
  • Command Line Utilities there are several command argument parsing frameworks all discuss here Swift for CLI
  • Run “serverless code” written in Swift on the cloud with IBM BlueMix OpenWisk

In the meantime is it possible to add a component like swift to a c9 workspace ?


#5

As a general rule of thumb, if it’s possible to do on Linux (from the command line and with a text editor) you can do it on Cloud9. My suggestion for you would be to:

  1. Get together a list of commands to configure a workspace for Swift development.
  2. Throw them into a bash script.
  3. Post the bash script and people can quickly develop Swift on C9 :smile:

If you want to go a step further, you can use the SDK for Cloud9 plugin development and improve some of the Swift language tooling there and then you’re all set!


#6

This is a script that will install the current version of Swift 3.0

#!/bin/bash
#
#  install_swift -- this script install's swift-3.0 for ubuntu 14 
#

#
# install dependencies
sudo apt-get update
sudo apt-get install clang libicu-dev 

#
# download
mkdir ~/downloads
cd ~/downloads
wget "https://swift.org/builds/swift-3.0-preview-1/ubuntu1404/swift-3.0-preview-1/swift-3.0-preview-1-ubuntu14.04.tar.gz"


#
# extract 
mkdir ~/swift
tar xzf swift-3.0-preview-1-ubuntu14.04.tar.gz -C ~/swift --strip-components 1


#
# update the PATH
echo 'export PATH=~/swift/usr/bin:$PATH' >>~/.profile 

echo "enter the command: 'source ~/.profile' to get access to the swift compiler from your current terminal"

#7

This is awesome. I was able to install Swift 3 and Vapor and get a simple swift server up and running. It’s an open project, here:

https://c9.io/utsira/swift-server

I chose Swift 3 developer preview 2 as the most recent release that Vapor supports.


#8

Here’s the readme from the above project, in case anyone else wants to get started with server-side-swift in Cloud9:

Creating a swift server on Cloud9

  1. Install Swift in your Cloud9 workspace. Almost all server-side-swift frameworks rely on Swift Package Manager, which is part of Swift 3. Pick the most recent Swift 3 release that is supported by the Swift server framework that you’d like to use. I went for Vapor, as it seemed to have a lot of documentation and tutorials, but there are lots of server-side-swift frameworks out there. Perfect and IBM’s Kitura seem popular too. I saw that Vapor supported Swift 3 Preview 2, so that’s the version of Swift I opted for. Copy the script below and paste it into a .sh file in your workspace. If necessary change the path to the Swift download and the tar unzip command to reflect the version of Swift you’re installing. I ran the script using source (nb just type what comes after the $ prompt):
    utsira:~/workspace $ source install-swift.sh
    Follow the instructions it gives you to be able to access Swift from the terminal, entering source ~/.profile
#!/bin/bash
#
#  install_swift -- this script install's swift-3.0 for ubuntu 14 
#

#
# install dependencies
sudo apt-get update
sudo apt-get install clang libicu-dev 

#
# download
mkdir ~/downloads
cd ~/downloads
wget "https://swift.org/builds/swift-3.0-preview-2/ubuntu1404/swift-3.0-PREVIEW-2/swift-3.0-PREVIEW-2-ubuntu14.04.tar.gz"
#
# extract 
mkdir ~/swift
tar xzf swift-3.0-PREVIEW-2-ubuntu14.04.tar.gz -C ~/swift --strip-components 1


#
# update the PATH
echo 'export PATH=~/swift/usr/bin:$PATH' >>~/.profile 

echo "enter the command: 'source ~/.profile' to get access to the swift compiler from your current terminal"
  1. A tip for working with Swift in Cloud9. By default, Cloud9 workspaces don’t show you the root folder ~, they show you ~/workspace. Click the settings cog in the Workspace browser pane on the left and make sure that Show root file system and Show hidden files are ticked.

  2. Initialize a new Swift package. The above script might have left you in the downloads directory, so move to the root cd .. if not already there. The workspace directory might be the best place to store your projects, so cd into it and make a directory for your project mkdir HelloWorld, or whatever you’re naming your project. cd into that directory cd HelloWorld/ and initialize it as a Swift package:
    utsira:~/HelloWorld $ swift package init --type executable

  3. Add a server-side-swift framework to the Package.swift file. Choose the version of the framework that matches the version of Swift you installed in step 1 (eg version 0.14 of Vapor is designed to run on swift-3.0-PREVIEW-2 which I installed with the above script. It’s important to get this right, as server-side-swift frameworks typically have lots of dependencies). Your file should look like this:

import PackageDescription
 
let package = Package(
    name: "HelloWorld",
    dependencies: [
        .Package(url: "https://github.com/qutheory/vapor.git", majorVersion: 0, minor: 14)
    ]
)
  1. Change your main.swift code to a Hello World server:
import Vapor
 
let app = Droplet()
 
app.get("/") { request in
    return "Hello, World"
}

app.serve()
  1. Build and run!
    utsira:~/HelloWorld $ swift build
    then
    utsira:~/HelloWorld $ .build/debug/HelloWorld

  2. You should see this terminal message: Starting server at 0.0.0.0:8080. Click the link and select Open to open it in a new tab. You should see Hello, world. Voila, a server running on Swift! Hit ctrl-c in the terminal pane to halt the server.


#9

This looks awesome! I think I may clean this up a tiny bit (just formatting consistency and such) and then try it out myself and if it’s easy enough and works for me then I’ll post it in the #how-to section if that’s alright with you :grin:


#10

Yeah, please do. I’m not sure TBH what the best environment for writing server-side-swift is. I was amazed at how easy it was to get “hello world” up and running in Cloud 9, but if you wanted to do more than that, you’d want code completion and compiler checking. Xcode still seems very tied to iOS/ OSX, and there are some strange stumbling blocks if you want to use it for server-side-swift. I saw that there was a Swift plugin being developed for the Atom editor, which could be promising. Things should get easier/ clearer once Swift 3 (and the Swift Package Manger) go golden in the Autumn. Would it be possible at all for cloud9 to add Swift code completion and compiler checking? Would a standard c9 server-side-swift template be something you’d consider? It seems like there’s quite a bit of momentum building behind it. I heard an IBM dev (they made the Kitura framework) call Swift “one of the three (!) languages IBM cares about”…


#11

Playing around with this some more, and you do get some code completion, certainly for the dependencies you’ve imported, plus some swift commands. I’m not sure what the pattern is in terms of what is and isn’t covered.

If people wanted a cloud-based swift compiler, I guess they could use the IBM swift sandbox before copying the code across to cloud9:

https://developer.ibm.com/swift/ibm-swift-sandbox/

I set up a second workspace to try to install IBM’s Kitura, but I haven’t got it to work unfortunately (I can’t install the Dispatch library).

I guess I should try Perfect too, so that I’ve tried the three biggest server-side-swift frameworks.


#12

Anyone interested in finding out more, IBM did the server-side swift presentation at this year’s WWDC, it’s a really interesting watch:

https://developer.apple.com/videos/play/wwdc2016/415/

btw The title of this thread should be changed to “Add Swift 3 as a language”, as all the server-side frameworks rely on the package manager that’s part of Swift 3.


#13

Now that the dispatch library is included with ubuntu Swift snapshots, I’ve managed to get IBM Kitura working in Cloud9 too. Here: https://ide.c9.io/utsira/swift-kitura