Realm Blog

Realm Objective-C & Swift 0.94


We just pushed version 0.94 of Realm Objective-C and Realm Swift. Along with many bug fixes and performance enhancements, this release improves support for Xcode 7 Beta 4, watchOS, Swift 2.0, Objective-C generics, and bitcode.

We’ve also exposed the ability to swap & move objects in an RLMArray or a List.

Finally, to allow us to make more informed product decisions moving forward, this release introduces the collection of development analytics.

Read on for an overview of all the changes included in 0.94.

Performance Improvements

RLMRealm notification listener threads should now consume less memory than ever before. This is part of an ongoing effort to reduce the memory footprint of apps using Realm.

Filtering and sorting results is now done lazily, which will further reduce the overhead of chaining queries together.

Support for New Apple Features

Nullability

The Objective-C API has been fully annotated for nullability semantics to provide enhanced compiler warnings and bridging to Swift. Here’s what that looks like when using Realm Objective-C from Swift:

// Before nullability annotations
class func ignoredProperties() -> [AnyObject]!

// After nullability annotations
class func ignoredProperties() -> [AnyObject]

Generics

RLMResults and RLMArrays now support native Objective-C generics if available (Xcode 7 or later), which should help catch more type errors at compile-time.

Here’s how you can make use of these new generics:

// Define a Company model with a generic array of employees
@interface Company : RLMObject
@property RLMArray<Employee *><Employee> *employees;
@end

// Retrieve all employees and store in a generic RLMResults
RLMResults<Employee *> *allEmployees = [Employee allObjects];

Here’s what the different components of the RLMArray property definition mean and why they are useful:

  • RLMArray: The property type.
  • <Object *>: The generic specialization. This helps prevent using the array with the wrong object type at compile-time.
  • <Object>: The protocol this RLMArray conforms to. This enables Realm to know how to specialize the schema of this model at runtime.

Objective-C generics are unfortunately type-erased, which means Realm can’t determine the specialization at runtime. This is why the protocol conformance declaration is still necessary, even though it’s unsightly. We apologize for the angle-bracket blindness!

Bitcode, watchOS & Swift 2.0

iOS & watchOS builds of Realm now include bitcode. Our zip archives distributed via this website, GitHub Releases, and Carthage now include builds for all these configurations:

  • Objective-C / Swift 1.2 / Swift 2.0 Beta 4
  • Mac / iOS / watchOS

Yikes! And people say Android is fragmented!

realm-cocoa-deal-with-it

Other Enhancements

  • The exceptions thrown in getters and setters are more informative.
  • Add -[RLMArray exchangeObjectAtIndex:withObjectAtIndex:] and List.swap(_:_:) to allow exchanging the location of two objects in the given RLMArray / List.
  • Add -[RLMArray moveObjectAtIndex:toIndex:] and List.move(from:to:) to allow moving objects in the given RLMArray / List.

Bugfixes

  • Processes crashing due to an uncaught exception inside a write transaction will
  • Fix incorrect results when querying for < or <= on ints that require 64 bits to represent with a CPU that supports SSE 4.2.
  • An exception will no longer be thrown when attempting to reset the schema version or encryption key on an open Realm to the current value.
  • Date properties on 32 bit devices will retain 64 bit second precision.
  • Wrap calls to the block passed to enumerate in an autoreleasepool to reduce memory growth when migrating a large amount of objects.
  • In-memory realms no longer write to the Documents directory on iOS or Application Support on OS X.

Analytics

Realm now asynchronously submits build information to Realm if running in an iOS Simulator or on OS X if a debugger is attached. Nothing is done when running on a physical iOS / watchOS device or if a debugger is not attached.

To be clear: this does not run when your app is in production or on your end-user’s devices; it will only run in the simulator or when a debugger is attached.

For more information, see PR #2276 which introduced this change.


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


Realm Team

At Realm, our mission is to help developers build better apps faster. We provide a unique set of tools and platform technologies designed to make it easy for developers to build apps with sophisticated, powerful features — things like realtime collaboration, augmented reality, live data synchronization, offline experiences, messaging, and more.

Everything we build is developed with an eye toward enabling developers for what we believe the mobile internet evolves into — an open network of billions of users and trillions of devices, and realtime interactivity across them all.

Get more development news like this