We just pushed a Realm Objective-C update to this website and to CocoaPods. Here’s what’s new!
Inheritance
You can now inherit from RLMObject
subclasses. For example, you can now do things like the following:
@interface Person : RLMObject
@property NSString *name;
@property int age;
@end
@interface Employee : Person
@property NSString *department;
@end
RLM_ARRAY_TYPE(Employee)
@interface Company : RLMObject
@property RLMArray<Employee> *employees;
@end
Each subclass is treated as an entirely distinct type containing all of the properties defined on it and all of its parent classes. This means that you can do things like [company.employees objectsWhere:@"name > 25"]
(querying an object based on a property defined in a parent class), but you cannot use an object of a subclass in a relationship where the parent is expected. That is, the following does not work:
@interface SalariedEmployee : Employee
@property int salary;
@end
SalariedEmployee *newEmployee = [SalariedEmployee createInDefaultRealmWithObject:...];
// Will throw exception "Attempting to insert wrong object type"
[company.employees addObject:newEmployee];
Primary Key Improvements
There’s now an objectForPrimaryKey:
method on RLMObject
subclasses which fetches the single object with the given primary key, or returns nil
if none exists. This is equivalent to [[ModelClass objectsWhere:@"primaryColumnName = %@", key] firstObject]
, but is clearer and a bit faster.
createOrUpdateInRealm:withObject:
no longer requires that all of the objects in the hierarchy have primary keys. This allows you to use it when you want to do things like create a new object with no primary key which references other objects that have primary keys and may or may not already exist.
Querying Improvements and Fixes
The performance of large queries has been greatly improved, especially for IN queries matching many items. Many queries are about twice as fast as before, and in some extreme cases are as much as 1000 times faster.
RLMArray
properties on RLMObject
s can now be sorted with arraySortedByProperty:ascending:
just like RLMArray
s returned from queries.
IN clauses in queries can now be used on any enumerable object (such as an RLMArray
returned from a query) rather than just NSArray
, and it’s no longer an error to have zero items in the IN clause.
Chaining queries works properly once again rather than ignoring all but the last query’s conditions (broken in 0.85.0).
Other stuff
Compiling Realm now requires Xcode 6.
NSNull
values in a dictionary are now correctly treated the same as missing keys when creating objects with createInRealm:withObject:
, and will use the default value defined for that property (if any).
readonly
properties on RLMObject
subclasses are now automatically ignored and do not have to be added to ignoredProperties
, and errors about not being able to persist property hash
when building for devices with Xcode 6 have been fixed.
Calling description
now returns a string telling you that the object has been deleted rather than throwing an exception.
Trying to add an object which is already persisted in a Realm to a different Realm now throws an exception rather than creating an uninitialized object in the target Realm. Use createInRealm:withObject:
to copy a persisted object to another Realm.
Adding objects to a Realm with -[RLMRealm addObject:]
is now about 20% faster.
Thanks for reading. Now go forth and build amazing apps with Realm! As always, we’re around on the mailing list, StackOverflow, GitHub, twitter and email.
Receive news and updates from Realm straight to your inbox