AsyncOpen

@available(iOS 14.0, macOS 11.0, tvOS 14.0, watchOS 7.0, *)
@propertyWrapper
public struct AsyncOpen : DynamicProperty

A property wrapper type that initiates a Realm.asyncOpen() for the current user which asynchronously open a Realm, and notifies states for the given process

Add AsyncOpen to your SwiftUI/View or SwiftUI/App, after a user is already logged in, or if a user is going to be logged in

@AsyncOpen(appId: "app_id", partitionValue: <partition_value>) var asyncOpen

This will immediately initiates a Realm.asyncOpen() operation which will perform all work needed to get the Realm to a usable state. (see Realm.asyncOpen() documentation)

This property wrapper will publish states of the current Realm.asyncOpen() process like progress, errors and an opened realm, which can be used to update the view

struct AsyncOpenView: View {
    @AsyncOpen(appId: "app_id", partitionValue: <partition_value>) var asyncOpen

    var body: some View {
       switch asyncOpen {
       case .notOpen:
           ProgressView()
       case .open(let realm):
           ListView()
              .environment(\.realm, realm)
       case .error(_):
           ErrorView()
       case .progress(let progress):
           ProgressView(progress)
       }
    }
}

This opened realm can be later injected to the view as an environment value which will be used by our property wrappers to populate the view with data from the opened realm

ListView()
   .environment(\.realm, realm)
  • A Publisher for AsyncOpenState, emits a state each time the asyncOpen state changes.

    Declaration

    Swift

    public var projectedValue: Published<AsyncOpenState>.Publisher { get }
  • This will cancel any notification from the property wrapper states

    Declaration

    Swift

    public func cancel()
  • Initialize the property wrapper

    Declaration

    Swift

    public init<Partition>(appId: String? = nil,
                           partitionValue: Partition,
                           configuration: Realm.Configuration? = nil,
                           timeout: UInt? = nil) where Partition: BSON

    Parameters

    appId

    The unique identifier of your Realm app, if empty or nil will try to retrieve latest singular cached app.

    partitionValue

    The BSON value the Realm is partitioned on.

    configuration

    The Realm.Configuration used when creating the Realm, user’s sync configuration for the given partition value will be set as the syncConfiguration, if empty the user configuration will be used.

    timeout

    The maximum number of milliseconds to allow for a connection to become fully established., if empty or nil no connection timeout is set.

  • Initialize the property wrapper for a flexible sync configuration.

    Declaration

    Swift

    public init(appId: String? = nil,
                configuration: Realm.Configuration? = nil,
                timeout: UInt? = nil)

    Parameters

    appId

    The unique identifier of your Realm app, if empty or nil will try to retrieve latest singular cached app.

    configuration

    The Realm.Configuration used when creating the Realm, user’s sync configuration for the given partition value will be set as the syncConfiguration, if empty the user configuration will be used.

    timeout

    The maximum number of milliseconds to allow for a connection to become fully established., if empty or nil no connection timeout is set.

  • Declaration

    Swift

    public mutating func update()