Realm v10.21.0 Release Notes
Release Date: 2022-01-10 // over 2 years ago-
โจ Enhancements
- โ Add
metadata
property toRLMUserProfile
/UserProfile
. - โ Add class
Projection
to allow creation of light weight view models out of Realm Objects.
```swift public class Person: Object { @Persisted var firstName = "" @Persisted var lastName = "" @Persisted var address: Address? = nil @Persisted var friends = List() }
public class Address: EmbeddedObject { @Persisted var city: String = "" @Persisted var country = "" }
class PersonProjection: Projection { //
Person.firstName
will have same name and type @Projected(\Person.firstName) var firstName // There will be the only String forcity
of the original objectAddress
@Projected(\Person.address.city) var homeCity // List will be mapped to list of firstNames @Projected(\Person.friends.projectTo.firstName) var firstFriendsName: ProjectedCollection }//
people
will contain projections for everyPerson
object in therealm
let people: Results = realm.objects(PersonProjection.self)* ๐ Greatly improve performance of reading AnyRealmValue and enum types from Realm collections. * ๐ Allow using Swift enums which conform to `PersistableEnum` as the value type for all Realm collections. * `AnyRealmCollection` now conforms to `Encodable`. * AnyRealmValue and PersistableEnum values can now be passed directly to an NSPredicate used in a filter() call rather than having to pass the rawValue (the rawValue is still allowed). * Queries on collections of PersistableEnums can now be performed with `where()`. * โ Add support for querying on the rawValue of an enum with `where()`. * ๐ `.count` is supported for Maps of all types rather than just numeric types in `where()`. * โ Add support for querying on the properties of objects contained in dictionaries (e.g. "[email protected] CONTAINS 'a'"). * ๐ Improve the error message for many types of invalid predicates in queries. * โ Add support for comparing `@allKeys` to another property on the same object. * โ Add `Numeric` conformance to `Decimal128`. * ๐ Make some invalid property declarations such as `List<AnyRealmValue?>` a compile-time error instead of a runtime error. * Calling `.sorted(byKeyPath:)` on a collection with an Element type which does not support sorting by keypaths is now a compile-time error instead of a runtime error. * `RealmCollection.sorted(ascending:)` can now be called on all non-Object/EmbeddedObject collections rather than only ones where the `Element` conforms to `Comparable`. * โ Add support for using user-defined types with `@Persistable` and in Realm collections by defining a mapping to and from a type which Realm knows how to store. For example, `URL` can be made persistable with: ```swift extension URL: FailableCustomPersistable { // Store URL values as a String in Realm public typealias PersistedType = String // Convert a String to a URL public init?(persistedValue: String) { self.init(string: persistedValue) } // Convert a URL to a String public var persistableValue: String { self.absoluteString } }
After doing this,
@Persisted var url: URL
is a valid property declaration on a Realm object. More advanced mappings can be done by mapping to an EmbeddedObject which can store multiple values.๐ Fixed
- Accessing a non object collection inside a migration would cause a crash
- #5633.
- Accessing a
Map
of objects dynamically would not handle nulled values correctly (since v10.8.0). where()
allowed constructing some nonsensical queries due to boolean comparisons returningQuery<T>
rather thanQuery<Bool>
(since v10.19.0).@allValues
queries on dictionaries accidentally did not require "ANY".- Case-insensitive and diacritic-insensitive modifiers were ignored when comparing the result of an aggregate operation to another property in a query.
Object.init(value:)
did not allow initializingRLMDictionary<NSString, RLMObject>
/Map<String, Object?>
properties with null values for map entries (since v10.8.0).@ObservedResults
did not refresh when changes were made to the observed collection. (since v10.6.0)
Compatibility
- Realm Studio: 11.0.0 or later.
- ๐ APIs are backwards compatible with all previous releases in the 10.x.y series.
- ๐ Carthage release for Swift is built with Xcode 13.2.1.
- CocoaPods: 1.10 or later.
- Xcode: 12.4-13.2.1.
- โ Add