BT

New Early adopter or innovator? InfoQ has been working on some new features for you. Learn more

Apple Open Sources Swift

| by Alex Blewitt Follow 2 Followers on Dec 03, 2015. Estimated reading time: 4 minutes |

Today, Apple open sourced the Swift programming language as promised in WWDC 2015. The code is available under Apple's newly created GitHub repository, under the Apache license, with the source code split into several different repositories:

There are also two separate packages available; the Swift package manager and the Swift build tools which can be used to build the Swift compiler and environment. There's more information about the package manager along with a community proposal for a new package manager (which shows how hard Apple is working at making this a successfully open source project). The PackageDescription module introduces a new type, Package, which represents metadata about a version and a name, as well as a list of dependencies. The implementation appears to be influenced with NPM, in that the dependencies are represented as source dependencies to remote Git repositories; when the build is executed, those dependencies are checked out, compiled to statically linked libraries and then included in the application. The package is kicked off by running a new swift build command, which downloads any dependencies defined in the Package.swift file. Dependencies are versioned using semantic versioning (which may be enforced in future), although it's not yet clear whether exact package versions can be specified or only a single version. The example given in the documentation shows:

import PackageDescription

let package = Package(
    name: "DeckOfPlayingCards",
    targets: [],
    dependencies: [
        .Package(url: "https://github.com/apple/example-package-fisheryates.git",
                 majorVersion: 1),
        .Package(url: "https://github.com/apple/example-package-playingcard.git",
                 majorVersion: 1),
    ]
)

Since Swift is built upon tools like LLVM and Clang, there are forks of swift-llvm, swift-clang, swift-lldb and swift-cmark which is used to generate documentation for the Swift source files. Unlike their SVN counterparts, these are hosted in Git and will be much easier to maintain in the future.

Swift aims to build a community by accepting contributions. A new blog provides information about Swift development, which may ultimately supersede the blog at Apple's main website. There is a community code of conduct (which is based on the one defined at contributor-covenant.org) as well as a number of mailing lists including swift-dev and swift-corelibs-dev. A number of pull requests have been merged already despite the project only having been publicly available for a few hours.

Because Swift libraries are copied into executables, the Apache License has a runtime library exception added which permits the application to be used without providing attribution:

As an exception, if you use this Software to compile your source code and portions of this Software are embedded into the binary product as a result, you may redistribute such product without providing attribution as would otherwise be required by Sections 4(a), 4(b) and 4(d) of the License.

This text is added at the end of the standard Swift license, which means that although it is based on the standard Apache License there may be some considerations necessary for legal re-approval. The idea of runtime exceptions is not new; for example, Oracle licenses Java under the GPL license but with a classpath exception that allows code to be linked without using the full GPL.

Finally, one of the main questions about Apple's open-sourcing of Swift is: would it run on other operating systems? The answer is yes; there is a Linux port and there are pre-built binaries for Ubuntu available from the Swift.org download page, although it isn't quite as full-featured as the OSX port. 

Swift on Linux does not depend on the Objective-C runtime nor includes it. While Swift was designed to interoperate closely with Objective-C when it is present, it was also designed to work in environments where the Objective-C runtime does not exist.

Fortunately, you can run and debug Swift applications on Linux using the REPL so it's possible to get started with Linux and Swift easily and quickly. There is some missing behaviour; for example, those things that require the Objective-C bridge (such as some String APIs that use NSString's implementation under the covers, or classes marked with @objc) will not work on the Linux port at the moment. There are also some disconnects between general C APIs such as variable args support and limited libdispatch functionality, which is being worked on the GitHub project.

Will you be interested in learning Swift now that it's available outside of the Apple ecosystem?

Rate this Article

Adoption Stage
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread
Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Discuss

Login to InfoQ to interact with what matters most to you.


Recover your password...

Follow

Follow your favorite topics and editors

Quick overview of most important highlights in the industry and on the site.

Like

More signal, less noise

Build your own feed by choosing topics you want to read about and editors you want to hear from.

Notifications

Stay up-to-date

Set up your notifications and don't miss out on content that matters to you

BT