Owen Zhao Owen Zhao - 6 months ago 142
Swift Question

How to build Realm using Swift 2.3?

I have already change toolchain to swift 2.3 by

export PATH=/Applications/Xcode-beta.app/Contents/Developer/Toolchains/Swift_2.3.xctoolchain/usr/bin:"${PATH}"

And did

Open the Xcode project -> Click on the Realm project -> RealmSwift target -> 'Build Settings' tab -> set Use Legacy Swift Language Version to Yes (if building for Swift 2.3) or No (if building for Swift 3).

as Build realm for Swift 3 & Xcode 8 says.

But what I get is still swift 3.0 version.

Any idea?

I looked into build.sh and found out the export path doesn't work as in xcrun swift, which was used by realm to get swift version, it was still 2.2 or 3.0, depending which toolchain was used.


To build Realm from the master branch with Swift 2.3, set the REALM_SWIFT_VERSION environment variable to 2.3 when building. For instance, to build for OS X:

REALM_SWIFT_VERSION=2.3 sh build.sh osx

Realm's build scripts will determine which Xcode version to use based on the value of the REALM_SWIFT_VERSION environment variable, so there's no need to modify your PATH variable.