ObservedSectionedResults

@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
@propertyWrapper
public struct ObservedSectionedResults<Key, ResultType> : DynamicProperty, BoundCollection where Key : _Persistable, Key : Hashable, ResultType : KeypathSortable, ResultType : RealmFetchable, ResultType : _ObservedResultsValue, ResultType : Identifiable

A property wrapper type that represents a sectioned results collection.

The sectioned results use the realm configuration provided by the environment value realmConfiguration if configuration is not set in the initializer.

Given @ObservedSectionedResults var v in SwiftUI, $v refers to a BoundCollection.

  • Declaration

    Swift

    public typealias Element = ResultType
  • Stores an NSPredicate used for filtering the SectionedResults. This is mutually exclusive to the where parameter.

    Declaration

    Swift

    @State
    public var filter: NSPredicate? { get nonmutating set }
  • Stores a type safe query used for filtering the SectionedResults. This is mutually exclusive to the filter parameter.

    Declaration

    Swift

    @State
    public var `where`: ((Query<ResultType>) -> Query<Bool>)? { get nonmutating set }
  • Initialize a ObservedSectionedResults struct for a given Projection type.

    Note

    The primary sort descriptor must be responsible for determining the section key.

    Declaration

    Swift

    public init<ObjectType: ObjectBase>(_ type: ResultType.Type,
                                        sectionKeyPath: KeyPath<ResultType, Key>,
                                        sortDescriptors: [SortDescriptor] = [],
                                        filter: NSPredicate? = nil,
                                        keyPaths: [String]? = nil,
                                        configuration: Realm.Configuration? = nil) where ResultType: Projection<ObjectType>, ObjectType: ThreadConfined

    Parameters

    type

    Observed type

    sectionKeyPath

    The keyPath that will produce the key for each section. For every unique value retrieved from the keyPath a section key will be generated.

    sortDescriptors

    A sequence of SortDescriptors to sort by.

    filter

    Observations will be made only for passing objects. If no filter given - all objects will be observed

    keyPaths

    Only properties contained in the key paths array will be observed. If nil, notifications will be delivered for any property change on the object. String key paths which do not correspond to a valid a property will throw an exception.

    configuration

    The Realm.Configuration used when creating the Realm. If empty the configuration is set to the defaultConfiguration

  • Initialize a ObservedSectionedResults struct for a given Projection type.

    Note

    The primary sort descriptor must be responsible for determining the section key.

    Declaration

    Swift

    public init<ObjectType: ObjectBase>(_ type: ResultType.Type,
                                        sectionBlock: @escaping ((ResultType) -> Key),
                                        sortDescriptors: [SortDescriptor] = [],
                                        filter: NSPredicate? = nil,
                                        keyPaths: [String]? = nil,
                                        configuration: Realm.Configuration? = nil) where ResultType: Projection<ObjectType>, ObjectType: ThreadConfined

    Parameters

    type

    Observed type

    sectionBlock

    A callback which returns the section key for each object in the collection.

    sortDescriptors

    A sequence of SortDescriptors to sort by.

    filter

    Observations will be made only for passing objects. If no filter given - all objects will be observed

    keyPaths

    Only properties contained in the key paths array will be observed. If nil, notifications will be delivered for any property change on the object. String key paths which do not correspond to a valid a property will throw an exception.

    configuration

    The Realm.Configuration used when creating the Realm. If empty the configuration is set to the defaultConfiguration

  • Initialize a ObservedSectionedResults struct for a given Object or EmbeddedObject type.

    Note

    The primary sort descriptor must be responsible for determining the section key.

    Declaration

    Swift

    public init(_ type: ResultType.Type,
                sectionKeyPath: KeyPath<ResultType, Key>,
                sortDescriptors: [SortDescriptor] = [],
                filter: NSPredicate? = nil,
                keyPaths: [String]? = nil,
                configuration: Realm.Configuration? = nil) where ResultType: Object

    Parameters

    type

    Observed type

    sectionKeyPath

    The keyPath that will produce the key for each section. For every unique value retrieved from the keyPath a section key will be generated.

    sortDescriptors

    A sequence of SortDescriptors to sort by.

    filter

    Observations will be made only for passing objects. If no filter given - all objects will be observed

    keyPaths

    Only properties contained in the key paths array will be observed. If nil, notifications will be delivered for any property change on the object. String key paths which do not correspond to a valid a property will throw an exception.

    configuration

    The Realm.Configuration used when creating the Realm. If empty the configuration is set to the defaultConfiguration

  • Initialize a ObservedSectionedResults struct for a given Object or EmbeddedObject type.

    Note

    The primary sort descriptor must be responsible for determining the section key.

    Declaration

    Swift

    public init(_ type: ResultType.Type,
                sectionBlock: @escaping ((ResultType) -> Key),
                sortDescriptors: [SortDescriptor] = [],
                filter: NSPredicate? = nil,
                keyPaths: [String]? = nil,
                configuration: Realm.Configuration? = nil) where ResultType: Object

    Parameters

    type

    Observed type

    sectionBlock

    A callback which returns the section key for each object in the collection.

    sortDescriptors

    A sequence of SortDescriptors to sort by.

    filter

    Observations will be made only for passing objects. If no filter given - all objects will be observed

    keyPaths

    Only properties contained in the key paths array will be observed. If nil, notifications will be delivered for any property change on the object. String key paths which do not correspond to a valid a property will throw an exception.

    configuration

    The Realm.Configuration used when creating the Realm. If empty the configuration is set to the defaultConfiguration

  • Initialize a ObservedSectionedResults struct for a given Object or EmbeddedObject type.

    Note

    The primary sort descriptor must be responsible for determining the section key.

    Declaration

    Swift

    public init(_ type: ResultType.Type,
                sectionBlock: @escaping ((ResultType) -> Key),
                sortDescriptors: [SortDescriptor] = [],
                where: ((Query<ResultType>) -> Query<Bool>)? = nil,
                keyPaths: [String]? = nil,
                configuration: Realm.Configuration? = nil) where ResultType: Object

    Parameters

    type

    Observed type

    sectionBlock

    A callback which returns the section key for each object in the collection.

    sortDescriptors

    A sequence of SortDescriptors to sort by.

    where

    Observations will be made only for passing objects. If no type safe query is given - all objects will be observed.

    keyPaths

    Only properties contained in the key paths array will be observed. If nil, notifications will be delivered for any property change on the object. String key paths which do not correspond to a valid a property will throw an exception.

    configuration

    The Realm.Configuration used when creating the Realm. If empty the configuration is set to the defaultConfiguration

  • Initialize a ObservedSectionedResults struct for a given Object or EmbeddedObject type.

    Note

    The primary sort descriptor must be responsible for determining the section key.

    Declaration

    Swift

    public init(_ type: ResultType.Type,
                sectionKeyPath: KeyPath<ResultType, Key>,
                sortDescriptors: [SortDescriptor] = [],
                where: ((Query<ResultType>) -> Query<Bool>)? = nil,
                keyPaths: [String]? = nil,
                configuration: Realm.Configuration? = nil) where ResultType: Object

    Parameters

    type

    Observed type

    sectionKeyPath

    The keyPath that will produce the key for each section. For every unique value retrieved from the keyPath a section key will be generated.

    sortDescriptors

    A sequence of SortDescriptors to sort by.

    where

    Observations will be made only for passing objects. If no type safe query is given - all objects will be observed.

    keyPaths

    Only properties contained in the key paths array will be observed. If nil, notifications will be delivered for any property change on the object. String key paths which do not correspond to a valid a property will throw an exception.

    configuration

    The Realm.Configuration used when creating the Realm. If empty the configuration is set to the defaultConfiguration

  • Initialize a ObservedSectionedResults struct for a given Object or EmbeddedObject type.

    Note

    The primary sort descriptor must be responsible for determining the section key.

    Declaration

    Swift

    public init(_ type: ResultType.Type,
                sectionKeyPath: KeyPath<ResultType, Key>,
                sortDescriptors: [SortDescriptor] = [],
                keyPaths: [String]? = nil,
                configuration: Realm.Configuration? = nil) where ResultType: Object

    Parameters

    type

    Observed type

    sectionKeyPath

    The keyPath that will produce the key for each section. For every unique value retrieved from the keyPath a section key will be generated.

    sortDescriptors

    A sequence of SortDescriptors to sort by.

    keyPaths

    Only properties contained in the key paths array will be observed. If nil, notifications will be delivered for any property change on the object. String key paths which do not correspond to a valid a property will throw an exception.

    configuration

    The Realm.Configuration used when creating the Realm. If empty the configuration is set to the defaultConfiguration

  • Initialize a ObservedSectionedResults struct for a given Object or EmbeddedObject type.

    Note

    The primary sort descriptor must be responsible for determining the section key.

    Declaration

    Swift

    public init(_ type: ResultType.Type,
                sectionBlock: @escaping ((ResultType) -> Key),
                sortDescriptors: [SortDescriptor],
                keyPaths: [String]? = nil,
                configuration: Realm.Configuration? = nil) where ResultType: Object

    Parameters

    type

    Observed type

    sectionBlock

    A callback which returns the section key for each object in the collection.

    sortDescriptors

    A sequence of SortDescriptors to sort by.

    keyPaths

    Only properties contained in the key paths array will be observed. If nil, notifications will be delivered for any property change on the object. String key paths which do not correspond to a valid a property will throw an exception.

    configuration

    The Realm.Configuration used when creating the Realm. If empty the configuration is set to the defaultConfiguration

  • Declaration

    Swift

    nonisolated public func update()