Realm Environment Variables
Environment .realm
Atlas Device SDK defines several environment variables in SwiftUI, we've already used one in this preview:
To use this data we change the preview in ConfigView.swift
. We can call realmWithData
as it's a static
member of PreviewProvider
now.
ConfigView.swift
struct ConfigView_Previews: PreviewProvider {
static var previews: some View {
let realm = realmWithData()
return ConfigView(habits: realm.objects(Habits.self).first!)
.environment(\.realm, realm)
}
}
The default Realm is created by the Atlas Device SDK and we can access it using the path \.realm
, but we can inject a new realm to other views down our hierarchy using:
.environment(\.realm, realm)
Environment .realmConfig
We can also change the default Realm Config and inject it using the environment with:
.environment(\.realmConfig, realmConfig)