问题
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.
回答1:
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.
回答2:
I have chosen @bdash answer as the best one. However, if you want to keep using swift 2.3 in command line. You can do
export TOOLCHAINS=com.apple.dt.toolchain.Swift_2_3
then use
sh build.sh osx-swift
@bdash answer only affects realm. So I think it is better than mine. My answer is inspired by Keith Smiley, who pointed out that I could use
xcrun --toolchain "com.apple.dt.toolchain.Swift_2_3" swiftc -v
to get 2.3 works.
the toolchain info is in /Applications/Xcode-beta.app/Contents/Developer/Toolchains/Swift_2.3.xctoolchain/ToolchainInfo.plist
来源:https://stackoverflow.com/questions/38888454/how-to-build-realm-using-swift-2-3