Overview

Skill Level: Any Skill Level

Swift developer

Ingredients

1. OSX:
  1.1. Xcode 7.2 or above
  1.2. Swift snapshot from Swift.org (https://swift.org/download/#snapshots)
 
2. Ubuntu:
  2.1. Docker

Step-by-step

  1. 1. Installation on OSX

    1.1. Download and install swift-2.2-branch and Trunk branch (swift-3.0)

    1.2. Change the default Swift toolchain from Xcode embedded to snapshot:

    $ export TOOLCHAINS=swift

    1.3. To verify the installed swift.

    $ xcrun –find swift
    > /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2016-03-24-a.xctoolchain/usr/bin/swift => Swift 3.0
    > /Library/Developer/Toolchains/swift-2.2.1-SNAPSHOT-2016-03-28-a.xctoolchain/usr/bin/swift => Swift 2.2.1 with Swift Package Manager

  2. u00a0

     

  3. 2. Installation on Ubuntu 14.04 / 15.10

    2.1. Follow Docker Document and refer the IBM Swift runtime Dockerfile to make sure the Docker is running.

    – Docker doc: (https://docs.docker.com/engine/installation/linux/ubuntulinux/)

    – IBM Swift runtime Dockerfile: (https://github.com/IBM-Swift/swift-runtime-container)

    2.2. Run by docker

    # docker run -i ibmcom/swift-ubuntu:latest /bin/sh

  4. checkVersion.swift

    create swift file and add following two line:

    import Foundation
    system(“swift –version”)

  5. 3. Run script (REPL) on OSX

    3.1. Run with latest snapshot (Swift 3.0)

    $ xcrun –toolchain org.swift.3020160324a swift run test.swift
    > Apple Swift version 3.0-dev (LLVM b010debd0e, Clang 3e4d01d89b, Swift 7182c58cb2)
    Target: x86_64-apple-macosx10.9

    3.2.Run with Swift 2.2.1

    $ xcrun –toolchain org.swift.22120160328a swift run test.swift
    > Apple Swift version 2.2-dev (LLVM ead37413ea, Clang 77f76b255c, Swift 9e755c224a)
    Target: x86_64-apple-macosx10.9

  6. Run script (REPL) on Ubuntu

    4.1. # docker run -it ibmcom/swift-ubuntu /bin/bash

    4.2. # swift run test.swift
    > Swift version 3.0-dev (LLVM b010debd0e, Clang 3e4d01d89b, Swift 7182c58cb2) Target: x86_64-unknown-linux-gnu

  7. 5. Verify the Swift runtime contains SPM (Swift Package Manager)

    5.1. $ swift build –version
    > Apple Swift Package Manager 0.1

    5.2. (if the swift runtime is from Xcode embedded)
    $ swift build –version
    > error: unable to invoke subcommand: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-build (No such file or directory)

  8. 6. Roll back to use Xcode embedded Swift runtime

    $ export TOOLCHAINS=
    $ swift –version
    > Apple Swift version 2.2 (swiftlang-703.0.18.1 clang-703.0.29)
    Target: x86_64-apple-macosx10.9

Join The Discussion