Functions

The following functions are available globally.

Combine

  • Creates a publisher that emits the object each time the object changes.

    Precondition

    The object must be a managed object which has not been invalidated.

    Declaration

    Swift

    @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
    public func valuePublisher<T>(_ object: T, keyPaths: [String]? = nil) -> RealmPublishers.Value<T> where T : RealmSwiftObject

    Parameters

    object

    A managed object to observe.

    keyPaths

    The publisher emits changes on these property keyPaths. If nil the publisher emits changes for every property.

    Return Value

    A publisher that emits the object each time it changes.

  • Creates a publisher that emits the collection each time the collection changes.

    Precondition

    The collection must be a managed collection which has not been invalidated.

    Declaration

    Swift

    @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
    public func valuePublisher<T>(_ collection: T, keyPaths: [String]? = nil) -> RealmPublishers.Value<T> where T : RealmCollection, T : RealmSubscribable

    Parameters

    object

    A managed collection to observe.

    keyPaths

    The publisher emits changes on these property keyPaths. If nil the publisher emits changes for every property.

    Return Value

    A publisher that emits the collection each time it changes.

  • Creates a publisher that emits the object each time the object changes.

    Precondition

    The object must be a managed object which has not been invalidated.

    Declaration

    Swift

    @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
    public func valuePublisher<T>(_ projection: T, keyPaths: [String]? = nil) -> RealmPublishers.Value<T> where T : ProjectionObservable, T : RealmSubscribable, T : ThreadConfined

    Parameters

    object

    A managed object to observe.

    keyPaths

    The publisher emits changes on these property keyPaths. If nil the publisher emits changes for every property.

    Return Value

    A publisher that emits the object each time it changes.

  • Creates a publisher that emits an object changeset each time the object changes.

    Precondition

    The object must be a managed object which has not been invalidated.

    Declaration

    Swift

    @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
    public func changesetPublisher<T>(_ object: T, keyPaths: [String]? = nil) -> RealmPublishers.ObjectChangeset<T> where T : RealmSwiftObject

    Parameters

    object

    A managed object to observe.

    keyPaths

    The publisher emits changes on these property keyPaths. If nil the publisher emits changes for every property.

    Return Value

    A publisher that emits an object changeset each time the object changes.

  • Creates a publisher that emits an object changeset each time the object changes.

    Precondition

    The object must be a projection.

    Declaration

    Swift

    @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
    public func changesetPublisher<T>(_ projection: T, keyPaths: [String]? = nil) -> RealmPublishers.ObjectChangeset<T> where T : ProjectionObservable, T : ThreadConfined

    Parameters

    projection

    A projection of Realm Object to observe.

    keyPaths

    The publisher emits changes on these property keyPaths. If nil the publisher emits changes for every property.

    Return Value

    A publisher that emits an object changeset each time the projection changes.

  • Creates a publisher that emits a collection changeset each time the collection changes.

    Precondition

    The collection must be a managed collection which has not been invalidated.

    Declaration

    Swift

    @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
    public func changesetPublisher<T>(_ collection: T, keyPaths: [String]? = nil) -> RealmPublishers.CollectionChangeset<T> where T : RealmCollection

    Parameters

    object

    A managed collection to observe.

    keyPaths

    The publisher emits changes on these property keyPaths. If nil the publisher emits changes for every property.

    Return Value

    A publisher that emits a collection changeset each time the collection changes.

Equatable

  • Returns a Boolean indicating whether the errors are identical.

    Declaration

    Swift

    public func == (lhs: Error, rhs: Error) -> Bool
  • Gets the components of a given key path as a string.

    Warning

    Objects that declare properties with the old @objc dynamic syntax are not fully supported by this function, and it is recommended that you use @Persisted to declare your properties if you wish to use this function to its full benefit.

    Example:

    let name = ObjectBase._name(for: \Person.dogs[0].name) // "dogs.name"
    // Note that the above KeyPath expression is only supported with properties declared
    // with `@Persisted`.
    let nested = ObjectBase._name(for: \Person.address.city.zip) // "address.city.zip"
    

    Declaration

    Swift

    public func _name<T>(for keyPath: PartialKeyPath<T>) -> String where T : RLMObjectBase
  • Gets the components of a given key path as a string.

    Warning

    Objects that declare properties with the old @objc dynamic syntax are not fully supported by this function, and it is recommended that you use @Persisted to declare your properties if you wish to use this function to its full benefit.

    Example:

    let name = PersonProjection._name(for: \PersonProjection.dogs[0].name) // "dogs.name"
    // Note that the above KeyPath expression is only supported with properties declared
    // with `@Persisted`.
    let nested = ObjectBase._name(for: \Person.address.city.zip) // "address.city.zip"
    

    Declaration

    Swift

    public func _name<O, T>(for keyPath: PartialKeyPath<T>) -> String where O : RLMObjectBase, O : RealmCollectionValue, T : Projection<O>
  • Returns the schema version for a Realm at a given local URL.

    Throws

    An NSError that describes the problem.

    Declaration

    Swift

    public func schemaVersionAtURL(_ fileURL: URL, encryptionKey: Data? = nil) throws -> UInt64

    Parameters

    fileURL

    Local URL to a Realm file.

    encryptionKey

    64-byte key used to encrypt the file, or nil if it is unencrypted.