github realm/realm-swift v10.21.0

latest releases: v10.50.0, v10.49.3, v10.48.2...
2 years ago

Enhancements

  • Add metadata property to RLMUserProfile/UserProfile.
  • Add class Projection to allow creation of light weight view models out of Realm Objects.
public class Person: Object {
    @Persisted var firstName = ""
    @Persisted var lastName = ""
    @Persisted var address: Address? = nil
    @Persisted var friends = List<Person>()
}

public class Address: EmbeddedObject {
    @Persisted var city: String = ""
    @Persisted var country = ""
}

class PersonProjection: Projection<Person> {
    // `Person.firstName` will have same name and type
    @Projected(\Person.firstName) var firstName
    // There will be the only String for `city` of the original object `Address`
    @Projected(\Person.address.city) var homeCity
    // List<Person> will be mapped to list of firstNames
    @Projected(\Person.friends.projectTo.firstName) var firstFriendsName: ProjectedCollection<String>
}

// `people` will contain projections for every `Person` object in the `realm`
let people: Results<PersonProjection> = 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. "dictProperty.@allValues.name 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:
    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 returning Query<T> rather than Query<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 initializing RLMDictionary<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.

Don't miss a new realm-swift release

NewReleases is sending notifications on new releases.