Build Realm for Swift 3 & Xcode 8

Build realm for Swift 3 & Xcode 8

Can you try these updated instructions, which should work for Beta 3?

  1. Clone the Realm Cocoa git repository: git clone https://github.com/realm/realm-cocoa.git
  2. Open the Xcode project. Click on the Realm project, then the RealmSwift target, then the 'Build Settings' tab, and set Use Legacy Swift Language Version to Yes (if building for Swift 2.3) or No (if building for Swift 3).
  3. From the directory containing the git repository, run the following command: sh build.sh TARGET, where TARGET is one of the following: ios-swift, osx-swift, tvos-swift, or watchos-swift, depending on what platform you are building for.
  4. Once the build has completed, go to the 'build' directory, then the directory named after the platform for which you built (e.g. 'ios').
  5. Open the 'swift-2.3' or 'swift-3.0' directory (depending on which version you built for).
  6. Drag RealmSwift.framework and Realm.framework into your project, as per step 2 in the instructions here, and do steps 3 and 4.

If these don't work please do post a comment.

RealmSwift with xCode 8

While there will be official support for Swift 3, currently you have to build Realm yourself using the instructions here.

How can you build RealmSwift for Swift 2.3 from sources using Xcode 8 IDE?

To my knowledge, it's not possible to override an Xcode subproject's SWIFT_VERSION within the IDE. You can specify SWIFT_VERSION when invoking xcodebuild, which should also propagate to Xcode subprojects, but I don't know of any way to do that from the Xcode GUI.

I'd recommend either using an alternative form of installation (CocoaPods, Carthage or prebuilt binaries) or to fork realm-cocoa, changing the value of SWIFT_VERSION and using that fork as your Xcode subproject.

I'd also recommend filing a radar so that Apple can be made aware of this unfortunate limitation!

To answer your other question, no there have never been any releases of Realm where SWIFT_VERSION was set to 2.3 in the Xcode project.

How to build Realm using Swift 2.3?

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.

Realm support for Swift 3.0

You can use Realm with Swift 3.0, but take into account that the current version is still absolutely experimental.

You can clone the master branch of the realm-cocoa repo from GitHub.

Or you can use Carthage:

github "realm/realm-cocoa.git" "master"

Or if you prefer CocoaPods:

pod 'RealmSwift', :git => 'https://github.com/realm/realm-cocoa.git', :branch => 'master'

If you use Carthage, remember that you must add Realm and RealmSwift frameworks manually (ignore the IBAnimatable framework):

Project configuration image

In fact, I have one of my projects with Xcode 8, Swift 3 and Realm, and it works perfectly :)

Realm support for Swift 3

I haven't tried it yet, but here is what should work.

Essentially, the compiler gives you a description of what went wrong. The framework was compiled with Swift 2.0, while your project or other files were compiled with Swift version 3.0 (which means you made the switch after upgrading to the new version of Xcode.

To fix this, you need to use the Realm framework compiled with a Swift 3.0 compiler. Since the Realm team doesn't yet provide a precompiled version compiled with Swift 3.0, you have to do so yourself. To do that, go to their Github repository, and follow the instructions in the README under "Building Realm":

Prerequisites:

  • Building Realm requires Xcode 7.3.
  • Building Realm documentation requires jazzy

Once you have all the necessary prerequisites, building
Realm.framework just takes a single command: sh build.sh build.
You'll need an internet connection the first time you build Realm to
download the core binary.

This should generate the Realm framework with the current compiler version, which you then just have to use to replace your current Realm framework with. After that, everything should compile as it used to.


As stated before, I don't know if this actually works, as I haven't tried it yet. I don't exactly know if Swift 3.0 is supported by Realm yet or if there are any other issues you could run into. So please let me know how this works out!



Related Topics



Leave a reply



Submit