ObservedResults
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
@propertyWrapper
@MainActor
public struct ObservedResults<ResultType> : DynamicProperty, BoundCollection where ResultType : KeypathSortable, ResultType : RealmFetchable, ResultType : _ObservedResultsValue, ResultType : Identifiable
A property wrapper type that represents the results of a query on a realm.
The results use the realm configuration provided by
the environment value realmConfiguration.
Unlike non-SwiftUI results collections, the ObservedResults is mutable. Writes to an ObservedResults collection implicitly perform a write transaction. If you add an object to the ObservedResults that the associated query would filter out, the object is added to the realm but not included in the ObservedResults.
Given @ObservedResults var v in SwiftUI, $v refers to a BoundCollection.
-
Declaration
Swift
public typealias Element = ResultType -
Stores an NSPredicate used for filtering the Results. This is mutually exclusive to the
whereparameter.Declaration
Swift
@State @MainActor public var filter: NSPredicate? { get nonmutating set } -
Stores a type safe query used for filtering the Results. This is mutually exclusive to the
filterparameter.Declaration
-
Initialize a
ObservedResultsstruct for a givenProjectiontype.Declaration
Swift
@MainActor public init<ObjectType: ObjectBase>(_ type: ResultType.Type, configuration: Realm.Configuration? = nil, filter: NSPredicate? = nil, keyPaths: [String]? = nil, sortDescriptor: SortDescriptor? = nil) where ResultType: Projection<ObjectType>, ObjectType: ThreadConfinedParameters
typeObserved type
configurationThe
Realm.Configurationused when creating the Realm, user’s sync configuration for the given partition value will be set as thesyncConfiguration, if empty the configuration is set to thedefaultConfigurationfilterObservations will be made only for passing objects. If no filter given - all objects will be observed
keyPathsOnly 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.sortDescriptorA sequence of
SortDescriptors to sort by -
Initialize a
ObservedResultsstruct for a givenObjectorEmbeddedObjecttype.Declaration
Swift
@MainActor public init(_ type: ResultType.Type, configuration: Realm.Configuration? = nil, filter: NSPredicate? = nil, keyPaths: [String]? = nil, sortDescriptor: SortDescriptor? = nil) where ResultType: ObjectParameters
typeObserved type
configurationThe
Realm.Configurationused when creating the Realm, user’s sync configuration for the given partition value will be set as thesyncConfiguration, if empty the configuration is set to thedefaultConfigurationfilterObservations will be made only for passing objects. If no filter given - all objects will be observed
keyPathsOnly 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.sortDescriptorA sequence of
SortDescriptors to sort by -
Initialize a
ObservedResultsstruct for a givenObjectorEmbeddedObjecttype.Declaration
Swift
@MainActor public init(_ type: ResultType.Type, configuration: Realm.Configuration? = nil, where: ((Query<ResultType>) -> Query<Bool>)? = nil, keyPaths: [String]? = nil, sortDescriptor: SortDescriptor? = nil) where ResultType: ObjectParameters
typeObserved type
configurationThe
Realm.Configurationused when creating the Realm, user’s sync configuration for the given partition value will be set as thesyncConfiguration, if empty the configuration is set to thedefaultConfigurationwhereObservations will be made only for passing objects. If no type safe query is given - all objects will be observed
keyPathsOnly 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.sortDescriptorA sequence of
SortDescriptors to sort by -
Declaration
Swift
nonisolated public func update()
View on GitHub
Install in Dash