Realm Blog

Realm Cocoa 0.89

We just pushed a Realm Objective-C update to this website and to CocoaPods. Here’s what’s new!


We’ve added support for transparently encrypting all of the data that Realm writes to disk. All you have to do is give Realm an encryption key to use, and everything will be encrypted when written and decrypted on read.

// Generate a random encryption key
NSMutableData *key = [NSMutableData dataWithLength:64];
SecRandomCopyBytes(kSecRandomDefault, key.length, (uint8_t *)key.mutableBytes);

// Open the encrypted Realm file
NSError *error;
RLMRealm *realm = [RLMRealm encryptedRealmWithPath:RLMRealm.defaultRealmPath
if (!realm) {
    // If the encryption key is wrong, `error` will say that it's an invalid database
    NSLog(@"Error opening realm: %@", error);

// Use the Realm as normal
RLMResults *dogs = [[Dog objectsInRealm:realm where:@"name contains 'Fido'"]];

// Or, if you prefer to have Realm remember the encryption key for a path
// and use it automatically:

// Set the encryption key for the default Realm
[RLMRealm setEncryptionKey:key forRealmsAtPath:RLMRealm.defaultRealmPath];

// Default Realm automatically uses the set encryption key
RLMResults *dogs = [Dog objectsWhere:@"name contains 'Fido'"];

Note that due to how the encryption is implemented, opening encrypted Realms with a debugger attached does not work, so you will probably want to only enable encryption in non-development builds.

There is a small performance hit (typically less than 20% slower) when using encrypted Realms due to having to encrypt and decrypt the data.

Bug Fixes

  • Default values for properties defined in the property declaration for Swift classes are now used by createObjectInRealm:withObject.
  • KVC-compliant objects which don’t have getters for their values are now supported by createObjectInRealm:withObject:.
  • Opening a Realm file which requires a migration when no migration has been supplied no longer leaves the database schema partially updated.
  • A major performance regression when querying on string properties has been fixed.
  • Adding circularly-linked objects to a Realm no longer requires manually setting the ivars to nil afterwards to avoid memory leaks.

Thanks for reading. Now go forth and build amazing apps with Realm! As always, we’re around on the mailing list, Stack Overflow, GitHub, and 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