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.

Initializers

Codable implementation

  • 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

APIs

  • get() Asynchronous

    This 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() Asynchronous

    The 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 type DataError when the data marked as required cannot be retrieved.

    Declaration

    Swift

    public func require() async throws -> ModelType