Realm Objective-C & Swift 1.1.0 – Official Swift 3 APIs & Xcode 8 Support

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.

We’re releasing version 1.1.0 of Realm Objective‑C and Realm Swift today, adding support for Xcode 8, Swift 2.3, Swift 3.0, with frameworks linked against iOS 10, macOS 10.12, tvOS 10 and watchOS 3. Also included in this release are some minor non-breaking API improvements, performance improvements and bug fixes. Read on to learn more!

Swift 3 API Refinements

Those of you keeping up with changes to Swift already know how big a jump Swift took from versions 2.x to 3.0!

We’ve audited Realm Swift’s public API in preparation for this and made some adjustments to reflect changes to Swift’s syntax and API design guidelines. We strived to strike a balance between conforming to the API guidelines without drastically changing ours APIs at their call site (i.e., in your code), so changes to your code should be minimal…

Here are some examples of how Realm Swift looks in Swift 2.2 and Swift 3.0:

// Swift 2.2/2.3
let config = Realm.Configuration(
  schemaVersion: 1,
  migrationBlock: { migration, oldSchemaVersion in
    migration.renamePropertyForClass(Person.className(), oldName: "yearsSinceBirth", newName: "age")
    migration.enumerate(Person.className()) { oldObject, newObject in
      // Migrate Person
    }
  }
)

let realm = try! Realm(configuration: config)
let sortedDogs = realm.objects(Dog.self).filter("color = 'tan'").sorted("name")
let jim = Person()
try! realm.write {
  jim.dogs.appendContentsOf(sortedDogs)
}

// Swift 3.0
let config = Realm.Configuration(
  schemaVersion: 1,
  migrationBlock: { migration, oldSchemaVersion in
    migration.renameProperty(onType: Person.className(), from: "yearsSinceBirth", to: "age")
    migration.enumerateObjects(ofType: Person.className()) { oldObject, newObject in
      // Migrate Person
    }
  }
)

let realm = try! Realm(configuration: config)
let sortedDogs = realm.objects(Dog.self).filter("color = 'tan'").sorted(byProperty: "name")
let jim = Person()
try! realm.write {
  jim.dogs.append(objectsIn: sortedDogs)
}

For simplicity, our documentation throughout the site has been updated to use Swift 3 exclusively. That includes code samples, long form docs and API docs.

API breaking changes

  • Deprecate migrateRealm: in favor of a new performMigrationForConfiguration:error: method that follows Cocoa’s NSError conventions.
  • Fix an issue where RLMResults used id instead of its generic type as the return type of subscript.

Enhancements

  • Improve error message when using NSNumber incorrectly in Swift models.
  • Further reduce the download size of the prebuilt static libraries.
  • Improve sort performance, especially on non-nullable columns.
  • Allow partial initialization of an object by initWithValue:, deferring required property checks until the object is added to a Realm.

Bug Fixes

  • Fix incorrect truncation of the constant value for queries of the form column < value for float and double columns.
  • Fix a crash when an aggregate is accessed as an Int8, Int16, Int32, or Int64.
  • Fix a race condition that could lead to a crash if an RLMArray or List was deallocated on a different thread than it was created on.
  • Fix a crash when the last reference to an observed object is released from within the observation.
  • Fix a crash when initWithValue: is used to create a nested object for a class with an uninitialized schema.
  • Enforce uniqueness for RealmOptional primary keys when using the value setter.

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