README - Shouldn't RootView var database be a @StateObject?
jackpal opened this issue · comments
Jack Palevich commented
The Readme has this code:
struct RootView: View {
// The database that all child views will automatically use
var database = try! Blackbird.Database.inMemoryDatabase()
...
But I think that has the potential issue of the database being recreated if/when RootView is recreated, which SwiftUI can do at whim.
I think the @StateObject decorator is supposed to be used:
struct RootView: View {
// The database that all child views will automatically use
@StateObject
var database = try! Blackbird.Database.inMemoryDatabase()
...
I notice that your actual example SwiftUI code doesn't have this issue because it stores the database in an App object rather than in a view.
marcoarment commented
You're right! Thanks. Fixed.