A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.mongodb.com/docs/realm-sdks/swift/latest/Structs/AutoOpen.html below:

AutoOpen Structure Reference

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

AutoOpen will try once to asynchronously open a Realm, but in case of no internet connection will return an opened realm for the given appId and partitionValue which can be used within our view. Add AutoOpen to your SwiftUI/View or SwiftUI/App, after a user is already logged in or if a user is going to be logged in

@AutoOpen(appId: "app_id", partitionValue: <partition_value>, timeout: 4000) var autoOpen

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 AutoOpenView: View {
    @AutoOpen(appId: "app_id", partitionValue: <partition_value>) var autoOpen

    var body: some View {
       switch autoOpen {
       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)

This property wrapper behaves similar as AsyncOpen, and in terms of declaration and use is completely identical, but with the difference of a offline-first approach.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4