ObservedSectionedResults
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
@propertyWrapper
@MainActor
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 @MainActor 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
-
Removes items from an
@ObservedSectionedResults
collection with a givenIndexSet
andResultsSection
.Declaration
Swift
@MainActor public func remove(atOffsets offsets: IndexSet, section: ResultsSection<Key, ResultType>) where ResultType: ObjectBase & ThreadConfined
Parameters
offsets
Index offsets in the section.
section
The section containing the items to remove.
-
Initialize a
ObservedSectionedResults
struct for a givenProjection
type.Note
The primary sort descriptor must be responsible for determining the section key.
Declaration
Swift
@MainActor 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
SortDescriptor
s 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 thedefaultConfiguration
-
Initialize a
ObservedSectionedResults
struct for a givenProjection
type.Note
The primary sort descriptor must be responsible for determining the section key.
Declaration
Swift
@MainActor 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
SortDescriptor
s 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 thedefaultConfiguration
-
Initialize a
ObservedSectionedResults
struct for a givenObject
orEmbeddedObject
type.Note
The primary sort descriptor must be responsible for determining the section key.
Declaration
Swift
@MainActor 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
SortDescriptor
s 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 thedefaultConfiguration
-
Initialize a
ObservedSectionedResults
struct for a givenObject
orEmbeddedObject
type.Note
The primary sort descriptor must be responsible for determining the section key.
Declaration
Swift
@MainActor 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
SortDescriptor
s 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 thedefaultConfiguration
-
Initialize a
ObservedSectionedResults
struct for a givenObject
orEmbeddedObject
type.Note
The primary sort descriptor must be responsible for determining the section key.
Declaration
Swift
@MainActor 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
SortDescriptor
s 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 thedefaultConfiguration
-
Initialize a
ObservedSectionedResults
struct for a givenObject
orEmbeddedObject
type.Note
The primary sort descriptor must be responsible for determining the section key.
Declaration
Swift
@MainActor 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
SortDescriptor
s 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 thedefaultConfiguration
-
Initialize a
ObservedSectionedResults
struct for a givenObject
orEmbeddedObject
type.Note
The primary sort descriptor must be responsible for determining the section key.
Declaration
Swift
@MainActor 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
SortDescriptor
s 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 thedefaultConfiguration
-
Initialize a
ObservedSectionedResults
struct for a givenObject
orEmbeddedObject
type.Note
The primary sort descriptor must be responsible for determining the section key.
Declaration
Swift
@MainActor 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
SortDescriptor
s 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 thedefaultConfiguration
-
Declaration
Swift
nonisolated public func update()