Google forked Swift

综合技术 2017-11-15

Swift Programming Language

Swift Package
Ubuntu 14.04
Ubuntu 16.04
Ubuntu 16.10

Welcome to Swift!

Swift is a high-performance system programming language. It has a clean and modern syntax, offers seamless access to existing C and Objective-C code and frameworks, and is memory safe by default.

Although inspired by Objective-C and many other languages, Swift is not itself a C-derived language. As a complete and independent language, Swift packages core features like flow control, data structures, and functions, with high-level constructs like objects, protocols, closures, and generics. Swift embraces modules, eliminating the need for headers and the code duplication they entail.

To learn more about the programming language, visit .

Contributing to Swift

Contributions to Swift are welcomed and encouraged! Please see the Contributing to Swift guide .

To be a truly great community, needs to welcome developers from all walks of life, with different backgrounds, and with a wide range of experience. A diverse and friendly community will have more great ideas, more unique perspectives, and produce more great code. We will work diligently to make the Swift community welcoming to everyone.

To give clarity of what is expected of our members, Swift has adopted the code of conduct defined by the Contributor Covenant. This document is used across many open source communities, and we think it articulates our values well. For more, see the Code of Conduct .

Getting Started

These instructions give the most direct path to a working Swift development environment. To build from source you will need 2 GB of disk space for the source code and over 20 GB of disk space for the build artifacts. A clean build can take multiple hours, but incremental builds will finish much faster.

System Requirements

macOS, Ubuntu Linux LTS, and the latest Ubuntu Linux release are the current supported host development operating systems.


To build for macOS, you need Xcode 9.2 beta 2 . The required version of Xcode changes frequently, and is often a beta release. Check this document or the host information on for the current required version.

You will also need CMake and Ninja , which can be installed via a package manager:


brew install cmake ninja


sudo port install cmake ninja

Instructions for installing CMake and Ninja directly can be foundbelow.


For Ubuntu, you'll need the following development dependencies:

sudo apt-get install git cmake ninja-build clang python uuid-dev libicu-dev icu-devtools libbsd-dev libedit-dev libxml2-dev libsqlite3-dev swig libpython-dev libncurses5-dev pkg-config libblocksruntime-dev libcurl4-openssl-dev autoconf libtool systemtap-sdt-dev tzdata

Note:LLDB currently requires at least swig-1.3.40 but will successfully build with version 2 shipped with Ubuntu.

Build instructions for Ubuntu 14.04 LTS can be found here .

Getting Sources for Swift and Related Projects

First create a directory for all of the Swift sources:

mkdir swift-source
cd swift-source

Note:This is important since update-checkout (see below) checks out repositories next to the Swift source directory. This means that if one clones Swift and has other unrelated repositories, update-checkout may not clone those repositories and will update them instead.

Via HTTPSFor those checking out sources as read-only, HTTPS works best:

git clone
./swift/utils/update-checkout --clone

Via SSHFor those who plan on regularly making direct commits, cloning over SSH may provide a better experience (which requires uploading SSH keys to GitHub ):

git clone
./swift/utils/update-checkout --clone-with-ssh

Building Swift

The build-script is a high-level build automation script that supports basic options such as building a Swift-compatible LLDB, building the Swift Package Manager, building for various platforms, running tests after builds, and more.

There are two primary build systems to use: Xcode and Ninja. The Xcode build system allows you to work in, but Ninja is a bit faster and supports more environments.

To build using Ninja, run:

utils/build-script --release-debuginfo

When developing Swift, it helps to build what you're working on in a debug configuration while building the rest of the project with optimizations. Below are some examples of using debug variants:

utils/build-script --release-debuginfo --debug-swift # Swift frontend built in debug
utils/build-script --release-debuginfo --debug-swift-stdlib # Standard library built in debug
utils/build-script --release-debuginfo --debug-swift --force-optimized-typechecker # Swift frontend sans type checker built in debug

Limiting the amount of debug code in the compiler has a very large impact on Swift compile times, and in turn the test execution time. If you want to build the entire project in debug, you can run:

utils/build-script --debug

For documentation of all available arguments, as well as additional usage information, see the inline help:

utils/build-script -h


To build using Xcode, specify the --xcode argument on any of the above commands. can be used to edit the Swift source code, but it is not currently fully supported as a build environment for SDKs other than macOS. The generated Xcode project does not integrate with the test runner, but the tests can be run with the 'check-swift' target.

Build Products

All of the build products are placed in swift-source/build/${TOOL}-${MODE}/${PRODUCT}-${PLATFORM}/ . If macOS Swift with Ninja in DebugAssert mode was built, all of the products would be in swift-source/build/Ninja-DebugAssert/swift-macosx-x86_64/ . It helps to save this directory as an environment variable for future use.

export SWIFT_BUILD_DIR="~/swift-source/build/Ninja-DebugAssert/swift-macosx-x86_64"


Once the first build has completed, ninja can perform fast incremental builds of various products. These incremental builds are a big timesaver when developing and debugging.

ninja swift

This will build the Swift compiler, but will not rebuild the standard library or any other target. Building the swift-stdlib target as an additional layer of testing from time to time is also a good idea. To build just the standard library, run:

ninja swift-stdlib

It is always a good idea to do a full build after using update-checkout .

Using Xcode

To open the Swift project in Xcode, open ${SWIFT_BUILD_DIR}/Swift.xcodeproj . It will auto-create a lot of schemes for all of the available targets. A common debug flow would involve:

  • Select the 'swift' scheme.
  • Pull up the scheme editor (⌘⇧<).
  • Select the 'Arguments' tab and click the '+'.
  • Add the command line options.
  • Close the scheme editor.
  • Build and run.
  • </).

Another option is to change the scheme to "Wait for executable to be launched", then run the build product in Terminal.

Build Failures

Make sure you are using thecorrect releaseof Xcode.

If you have changed Xcode versions but still encounter errors that appear to be related to the Xcode version, try passing --rebuild to build-script .

When a new version of Xcode is released, you can update your build without recompiling the entire project by passing the --reconfigure option.

Make sure all repositories are up to date with the update-checkout command described above.

Testing Swift

See docs/ , in particular the section on .

Learning More

Be sure to look through the [docs/] docs directory for more information about the compiler. In particular, the document on Debugging The Compiler , and Continuous are very helpful to understand before submitting your first PR.

Building Documentation

To read the compiler documentation, start by installing the Sphinx documentation generator tool by running the command:

easy_install -U Sphinx

Once complete, you can build the Swift documentation by changing directory into docs and typing make . This compiles the .rst files in the docs directory into HTML in the docs/_build/html directory.

Many of the docs are out of date, but you can see some historical design documents in the docs directory.

Another source of documentation is the standard library itself, located in stdlib . Much of the language is actually implemented in the library (including Int ), and the standard library gives some examples of what can be expressed today.

Build Dependencies


CMake is the core infrastructure used to configure builds of Swift and its companion projects; at least version 3.4.3 is required.

On macOS, you can download the CMake Binary Distribution , bundled as an application, copy it to /Applications , and add the embedded command line tools to your PATH :

export PATH=/Applications/$PATH

On Linux, if you have not already installed Swift'sdevelopment dependencies, you can download and install the CMake package separately using the following command:

sudo apt-get install cmake


Ninja is the current recommended build system for building Swift and is the default configuration generated by CMake. Pre-built packages are available for macOS and Linux distributions. You can also clone Ninja next to the other projects and it will be bootstrapped automatically:


git clone && cd ninja
git checkout release


git clone && cd ninja
git checkout release


联想和 Google 合作的 Daydream VR 一体机将在今年第二季度发售... Google 在去年的 I/O 大会上宣布 将和联想、HTC 推出 Daydream VR 一体机产品,在 CES 2018 上,联想终于公布了它们与 Google 合作的成果。之前我们报道过 Mirage Solo通过 FCC 认证 的消息,今次这款产品终于亮相了。 Mirage...
Where human intelligence outperforms AI David Kline Contributor David Kline is a journalist, author and intellectual property strategist. More posts by this contributor...
谷歌DeepMind首度放出纪录电影《AlphaGo》预告片... 就在刚才,DeepMind 的官方 Twitter 发出一条推文,发布了纪录片《AlphaGo》的预告片。其实该纪录片在 2017 年 4 月 21 日就在美国纽约的翠贝卡电影节上进行了小范围点映,获得了极佳的反响。 以下是 字幕 : 围棋是这个世界上历史最悠久的棋盘游戏,...
Google incubator’s New York City subway app ... Crowdsourced navigation appslike Waze are helpful for avoiding the real-world hazards that conventional apps don't mention. But what if you use m...
谷歌商店付费用户增长三成 超越苹果成为全球最大... 【TechWeb报道】9月25日消息,在人们印象中,谷歌商店用户一直不如苹果用户多。但近日谷歌官方对外宣布,谷歌商店付费用户已经从去年增长了三成,Google Play现在成为全球最大应用商店。 据报道,谷歌商店亚太地区负责人桑德斯公开表示,得益于更便利的支付方式,谷歌商店去年的付费用户增...