Realm Objective-C & Swift 2.0 – Mobile Platform Support

We’re releasing version 2.0 of Realm Objective‑C and Realm Swift today, adding support for the Realm Mobile Platform. Also included in this release is one source breaking change for Swift 3 and bug fixes. Read on to learn more!

Realm Mobile Platform Extensions

If you haven’t read the Realm Mobile Platform launch post yet, please do that now so we can get back to the technical cocoa bits! (err, nibs? 😄)

Let’s start with a quick look at what it takes to configure a synchronized Realm:

// Authenticating the User
User.authenticate(with: .google("google token"),
                  server: URL(string: "https://realm.example.com:9443")) { user, error in
  if let user = user {
    // Opening a remote Realm
    let realmURL = URL(string: "realm://realm.example.com:9080/~/userRealm")!
    let config = Realm.Configuration(syncConfiguration: (user, realmURL))
    let realm = try! Realm(configuration: config)
    // Any changes made to this Realm will be synced across all devices!
  } else if let error = error {
    // handle error
  }
}

That’s it! Once a Realm is opened like this, any changes made to it will be automatically synchronized across all other devices for that user.

Back to technical bits. To support the Mobile Platform, we’ve added some new classes and APIs:

Sync User & Credential

Sync Users are a central concept when dealing with synchronized Realms. Every Realm is associated with a user. The user can be authenticated to a Realm via a username/password credential or through a number of additional authentication methods (Google, Facebook, iCloud, etc.). See docs on users for details.

Sync Configuration

To configure a synchronized Realm, you must set the syncConfiguration property of RLMRealmConfiguration/Realm.Configuration with the user and the remote realm URL (e.g. realm://realm.example.com:9080/~/userRealm). See our docs for more details.

Sync Manager & Session

The sync manager (RLMSyncManager/SyncManager) is a singleton (for the time being) that manages all synchronized Realms. You’ll mostly interact with it to set the sync engine’s log level, or to specify a global error handler.

Each synchronized Realm has a corresponding session (RMLSyncSession/SyncSession) which can provide further information about its state. We intend to attach more information to this in upcoming releases.

Platform Extensions are in Beta

Although the underlying technology for Realm synchronization has been built, refined and stabilized over the last 5 years, we want to make sure we get the APIs right before commiting to them. So we’re releasing the platform extensions as a beta. These APIs will change in future releases. We’re doing this to make sure we end up with the best possible product.

If your app doesn’t use the platform extensions, you can continue to count on the reliability of Realm just like you always have. The platform extensions have been designed in a way that clearly differentiates from using Realm entirely locally or using a synchronized Realm, so this should be easy to identify if your app relies on any of the beta components.

A (mostly) non-breaking 2.0 release

This is a major version bump for our frameworks to reflect the magnitude of the new features and capabilities included in this release. However, we’ve chosen to not introduce API breaking changes, because we realize this release comes just a few months after our 1.0 release and we value the time it takes for you, our users, to update your apps for API changes. With one exception… In Realm 1.1.0 we introduced official Swift 3 APIs and the most common feedback we got there was how it wasn’t ideal that RealmSwift.Error conflicted with the standard library Swift.Error. So by popular demand, we’ve nested our Error into a Realm extension, and this is the only source-breaking change in this release.

Note that Realm Objective-C and Swift 2.0 introduces a new file format that allows us to gain performance improvements and fix some bugs. Files written by Realm 2.0 cannot be read by 1.x or earlier versions. Old files can still be opened.

Removing some extra files

The .log, .log_a and .log_b files no longer exist and the state tracked in them has been moved to the main Realm file. This reduces the number of open files needed by Realm, improves performance of both opening and writing to Realms, and eliminates a small window where committing write transactions would prevent other processes from opening the file.

Bug Fixes

  • Fix an assertion failure when sorting by zero properties.
  • Fix a mid-commit crash in one process also crashing all other processes with the same Realm open.
  • Properly initialize new nullable float and double properties added to existing objects to null rather than 0.
  • Fix a stack overflow when objects with indexed string properties had very long common prefixes.
  • Fix a race condition which could lead to crashes when using async queries or collection notifications.
  • Fix a bug which could lead to incorrect state when an object which links to itself is deleted from the Realm.

Q: Can I use Realm with its newly open sourced core storage engine?

Yes! You can build and use Realm as an embedded database built 100% from open source components. Although the installation steps are a bit more involved than pod install, but you can follow the instructions listed in the readmes for both realm-core and realm-cocoa.

We’re working on adding a way to install entirely from source using CocoaPods in the next few weeks. Stay tuned!

We’d like to remind you that we will continue to support Xcode 7.3.1 and Swift 2.2 as long as we can, but encourage all our users to migrate to Xcode 8 as soon as possible.


Thanks for reading. Now go forth and build amazing apps with Realm! As always, we’re around on Stack Overflow, GitHub, or Twitter.