Skip to content
Discussion options

You must be logged in to vote

Hi @kevvdevv, sorry I led you astray. The problem is that in a preview like this:

#Preview {
  @Previewable @FetchAll var values = 
  let _ = prepareDependencies {  }
  SomeView()
}

…is transformed into something like this:

struct WrapperView: View {
  @FetchAll var values = 
  var body: some View {
    let _ = prepareDependencies {  }
    SomeView()
  }
}

And so you can see that @FetchAll is unfortunately accessed before prepareDependencies.

The only workaround I can think of is to extract your view into a separate view so that it can delay when @FetchAll is actually accessed:

#Preview {
  let _ = prepareDependencies {
    $0.defaultDatabase = try! appDatabase()
  }
  InnerView()
}
p…

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
3 replies
@mbrandonw
Comment options

Answer selected by kevvdevv
@kevvdevv
Comment options

@kevvdevv
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants