LazyReference
public class LazyReference<ModelType> : Codable, _LazyReferenceValue where ModelType : Model
This class represents a lazy reference to a Model
, meaning that the reference
may or may not exist at instantiation time.
The default implementation DefaultModelProvider
only handles in-memory data, therefore get()
and
require()
will simply return the current reference
.
-
Declaration
Swift
public init(modelProvider: AnyModelProvider<ModelType>)
-
Declaration
Swift
public convenience init(_ reference: ModelType?)
-
Declaration
Swift
public convenience init(identifiers: [LazyReferenceIdentifier]?)
-
Decodable implementation is delegated to the ModelProviders.
Declaration
Swift
required convenience public init(from decoder: Decoder) throws
-
Encodable implementation is delegated to the underlying ModelProviders.
Declaration
Swift
public func encode(to encoder: Encoder) throws
-
get()
AsynchronousThis function is responsible for retrieving the model reference. In the default implementation this means simply returning the existing
reference
, but different storage mechanisms can implement their own logic to fetch data, e.g. from DataStore’s SQLite or AppSync.Declaration
Swift
public func get() async throws -> ModelType?
Return Value
the model
reference
, if it exists. -
require()
AsynchronousThe equivalent of
get()
but aimed to retrieve references that are considered non-optional. However, referential integrity issues and/or availability constraints might affect how required data is fetched. In such scenarios the implementation must throw an error to communicate to developers why required data could not be fetched.Throws
an error of typeDataError
when the data marked as required cannot be retrieved.Declaration
Swift
public func require() async throws -> ModelType