MirroredStorage

extension MoEngageStorage.MirroredStorage: MoEngageStorage.ReadOnlyLocation
where
    Primary: MoEngageStorage.ReadOnlyLocation & MoEngageStorage.WriteOnlyLocation,
    Mirror: MoEngageStorage.ReadOnlyLocation & MoEngageStorage.WriteOnlyLocation,
    Primary.Input == Mirror.Input,
    PrimaryStored == Primary.Stored,
    MirrorStored == Mirror.Stored,
    Primary.Stored == Mirror.Stored,
    Primary.Stored == Primary.Saved,
    Mirror.Stored == Mirror.Saved
extension MoEngageStorage.MirroredStorage: MoEngageStorage.WriteOnlyLocation
where
    Primary: MoEngageStorage.WriteOnlyLocation,
    Mirror: MoEngageStorage.WriteOnlyLocation,
    Primary.Saved == Mirror.Saved,
    Primary.Output == Mirror.Output,
    Primary.Output == Void
extension MoEngageStorage.MirroredStorage: MoEngageStorage.MigratableLocation
where
    Primary: MoEngageStorage.MigratableLocation,
    Mirror: MoEngageStorage.MigratableLocation

Available where Primary: MoEngageStorage.ReadOnlyLocation & MoEngageStorage.WriteOnlyLocation, Mirror: MoEngageStorage.ReadOnlyLocation & MoEngageStorage.WriteOnlyLocation, Primary.Input == Mirror.Input, PrimaryStored == Primary.Stored, MirrorStored == Mirror.Stored, Primary.Stored == Mirror.Stored, Primary.Stored == Primary.Saved, Mirror.Stored == Mirror.Saved

  • Reads and synchronises the primary and mirror locations.

    • From an extension: reads from the mirror location only, wrapping any error in OperationError/mirror(_:).
    • Without an app group: reads from the primary location only, wrapping any error in OperationError/primary(_:).
    • With an app group: reads both locations, wrapping errors as OperationError/primary(_:) or OperationError/mirror(_:) respectively; reconciles via reconcile and writes the result back to both (write-back failures are silently suppressed).

    Throws

    OperationError identifying which location failed.

    Declaration

    Swift

    public func read(
        withInput input: Primary.Input,
        fromInstance sdkInstance: isolated MoEngageSDKInstance = #isolation
    ) throws(ReadError) -> Primary.Stored

    Parameters

    input

    Unused (Void).

    sdkInstance

    The isolated SDK instance providing context.

    Return Value

    The reconciled stored value.

Available where Primary: MoEngageStorage.WriteOnlyLocation, Mirror: MoEngageStorage.WriteOnlyLocation, Primary.Saved == Mirror.Saved, Primary.Output == Mirror.Output, Primary.Output == Void

  • Writes the value to both locations according to the current process context.

    Operations are attempted sequentially; the first failure is thrown immediately and the remaining write (if any) is not attempted:

    • primary is written first when not running inside an extension; failure is wrapped in OperationError/primary(_:) and rethrown.
    • mirror is written when an appGroupID is configured; failure is wrapped in OperationError/mirror(_:) and rethrown.

    Throws

    OperationError identifying which location failed.

    Declaration

    Swift

    public func write(
        _ value: Primary.Saved,
        toInstance sdkInstance: isolated MoEngageSDKInstance = #isolation
    ) throws(WriteError)

    Parameters

    value

    The value to persist.

    sdkInstance

    The isolated SDK instance to write to.

Available where Primary: MoEngageStorage.MigratableLocation, Mirror: MoEngageStorage.MigratableLocation

  • Removes the value from both locations according to the current process context.

    Operations are attempted sequentially; the first failure is thrown immediately and the remaining removal (if any) is not attempted:

    • primary is removed first when not running inside an extension; failure is wrapped in OperationError/primary(_:) and rethrown.
    • mirror is removed when an appGroupID is configured; failure is wrapped in OperationError/mirror(_:) and rethrown.

    Throws

    OperationError identifying which location failed.

    Declaration

    Swift

    public func remove(
        fromInstance sdkInstance: isolated MoEngageSDKInstance = #isolation
    ) throws(RemoveError)

    Parameters

    sdkInstance

    The isolated SDK instance to remove from.