Skip to content
Discussion options

You must be logged in to vote

Hi @pahnev, there are a number of approaches to this, but we personally feel like these kinds of wrapper objects to hide the database from your codebase aren't worth the effort.

If you really want the wrapper to work for you, you will need it to return FetchOne/FetchAll/Fetch types, not just the data, so that you can retain observability. Here is an example of a SwiftUI view that gets its @FetchOne var reminder from a wrapper object like you outlined above:

class Wrapper {
  func reminder(id: UUID) -> FetchOne<Reminder?> {
    FetchOne(Reminder.where { $0.id.eq(id) })
  }
}

import SwiftUI
struct ReminderDetailView: View {
  @FetchOne var reminder: Reminder?
  init(id: UUID, wrapper: Wrapper

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@pahnev
Comment options

@mbrandonw
Comment options

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