ThreadConfined

public protocol ThreadConfined

Objects of types which conform to ThreadConfined can be managed by a Realm, which will make them bound to a thread-specific Realm instance. Managed objects must be explicitly exported and imported to be passed between threads.

Managed instances of objects conforming to this protocol can be converted to a thread-safe reference for transport between threads by passing to the ThreadSafeReference(to:) constructor.

Note that only types defined by Realm can meaningfully conform to this protocol, and defining new classes which attempt to conform to it will not make them work with ThreadSafeReference.

  • The Realm which manages the object, or nil if the object is unmanaged.

    Unmanaged objects are not confined to a thread and cannot be passed to methods expecting a ThreadConfined object.

    Declaration

    Swift

    var realm: Realm? { get }
  • Indicates if the object can no longer be accessed because it is now invalid.

    Declaration

    Swift

    var isInvalidated: Bool { get }
  • Indicates if the object is frozen.

    Frozen objects are not confined to their source thread. Forming a ThreadSafeReference to a frozen object is allowed, but is unlikely to be useful.

    Declaration

    Swift

    var isFrozen: Bool { get }
  • Returns a frozen snapshot of this object.

    Unlike normal Realm live objects, the frozen copy can be read from any thread, and the values read will never update to reflect new writes to the Realm. Frozen collections can be queried like any other Realm collection. Frozen objects cannot be mutated, and cannot be observed for change notifications.

    Unmanaged Realm objects cannot be frozen.

    Warning

    Holding onto a frozen object for an extended period while performing write transaction on the Realm may result in the Realm file growing to large sizes. See Realm.Configuration.maximumNumberOfActiveVersions for more information.

    Declaration

    Swift

    func freeze() -> Self
  • Returns a live (mutable) reference of this object. Will return self if called on an already live object.

    Declaration

    Swift

    func thaw() -> Self?

Available where Self: ObjectBase

  • bind(_:) Extension method

    Create a Binding for a given property, allowing for automatically transacted reads and writes behind the scenes.

    This is a convenience method for SwiftUI views (e.g., TextField, DatePicker) that require a Binding to be passed in. SwiftUI will automatically read/write from the binding.

    Declaration

    Swift

    public func bind<V>(_ keyPath: ReferenceWritableKeyPath<Self, V>) -> Binding<V> where V : _Persistable, V : Equatable