Realm ObjC & Swift 2.7: Permission APIs, Fast Reconnects, Password Change & Bug Fixes!

We’re releasing version 2.7 of Realm Objective‑C and Realm Swift today. In this release, we’re introducing improved permission APIs, faster reconnects, password change and applying a few bug fixes to keep your apps running strong.

Improved Permission APIs

We’re introducing new APIs for changing and retrieving permissions for synchronized Realms.

These APIs are intended to replace the existing Realm Object-based permissions system that were introduced in 2.0.4 and 2.4.4.

For example, the previous way to grant or revoke permissions was to create a {RLM}SyncPermissionChange object in the user’s managementRealm().

You could then observe that “change” object to be notified when the server had processed it, and whether or not the operation was successful.

let permissionChange = SyncPermissionChange(realmURL: realmURL,    // The remote Realm URL on which to apply the changes
                                            userID: anotherUserID, // The user ID for which these permission changes should be applied
                                            mayRead: true,         // Grant read access
                                            mayWrite: true,        // Grant write access
                                            mayManage: false)      // Grant management access

let managementRealm = try! user.managementRealm()
try! managementRealm.write {
  managementRealm.add(permissionChange)
}
// Wait for server response
token = permissionChange.addNotificationBlock { _ in
  switch permissionChange.status {
  case .notProcessed: break // handle case
  case .success: break // handle case
  case .error: break // handle case
  }
  print(permissionChange.statusMessage) // contains error or informational message
}

Get more development news like this

Retrieving permissions used a separate Realm (SyncUser.permissionRealm()) and a separate model type (SyncPermission).

let permissionRealm = try! user.permissionRealm()
let permissions = permissionRealm.objects(SyncPermission.self)
token = permissions.addNotificationBlock { _ in
  // permissions updated
}

These APIs have now been deprecated in favor of a simpler family of permission APIs that don’t require knowledge about how the internal transport mechanism is implemented.

There’s now a single {RLM}SyncPermissionValue type that should be used to apply, revoke and retrieve permissions:

// Applying permissions
let permission = SyncPermissionValue(realmPath: realmPath,
                                     userID: anotherUserID,
                                     accessLevel: .write)
user.applyPermission(permission) { error in
  if let error = error {
    // handle error
    return
  }
  // success!
}
// Retrieving permissions
user.retrievePermissions { permissions, error in
  if let error = error {
    // handle error
    return
  }
  // success! access permissions
}

You’ll find more documentation for using Realm’s Permissions APIs in the Access Control section of our docs.

These APIs require any edition of the Realm Object Server 1.1.0 or later.

Faster Reconnects

This release detects changes in connectivity status via the Reachability framework to instantly attempt a reconnection with the object server if the connection was not sustained.

Previously, the time before reconnection occurred was dependent on how long it had been since the connection was lost due to our exponential backoff reconnection algorithm.

Password Change

Users can now change their passwords using the -[RLMSyncUser changePassword:completion:] API if using Realm’s ‘password’ authentication provider. This API requires any edition of the Realm Object Server 1.4.0 or later.

Other Enhancements

  • {RLM}SyncConfiguration now has an enableSSLValidation property (and default parameter in the Swift initializer) to allow SSL validation to be specified on a per-server basis.
  • Transactions between a synced Realm and a Realm Object Server can now exceed 16 MB in size.

Bug Fixes

  • Support Realm model classes defined in Swift with overridden Objective-C names (e.g. @objc(Foo) class SwiftFoo: Object {}).
  • Fix -[RLMMigration enumerateObjects:block:] returning incorrect oldObject objects when enumerating a class name after previously deleting a newObject.
  • Fix an issue where Realm.asyncOpen(...) would fail to work when opening a synchronized Realm for which the user only had read permissions.
  • Using KVC to set a List property to nil now clears it to match the behavior of RLMArray properties.
  • Fix crash from !m_awaiting_pong assertion failure when using synced Realms.
  • Fix poor performance or hangs when performing case-insensitive queries on indexed string properties that contain many characters that don’t differ between upper and lower case (e.g. numbers, punctuation).

iOS 7 Support

We’d like to remind you that we will continue to support a minimum target iOS version of 7.0 as long as we can, but will be increasing the minimum target iOS version to 8.0 in a future release.


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