Closed skrew closed 4 years ago
Hello @skrew!
You're entering uncharted territory, I admit. I lack experience about SwiftUI so I can't really answer your first question.
I may help for your second question, though. It its current implementation, @DatabasePublished tracks a single request, which can not change. If the request changes over time, you may have to put DatabasePublished aside, and instead create a publisher of requests (driven by your UI), and convert it to a publisher of database values with switchToLatest. Gross untested sample code:
let request = ... // Publisher of QueryInterfaceRequest<Channel>
let channels = request.switchToLatest {
$0.observationForAll().publisher(in: dbQueue)
}
channels.sink(
receiveCompletion: { _ in },
receiveValue: { channel in print("fresh channels: \(channels)") })
This is basically the technique used for the "toggle ordering" button in the RxGRDB demo app.
Maybe @DatabasePublished could be made able to track a publisher of requests instead of a single request. Your own experience, suggested changes, maybe motivated pull requests will be welcomed!
No news is good news: I assume the previous answer was able to unblock you.
Hi Gwendal,
One day, one question π
Since you wanted concrete cases of use... π
I'm still evaluating
SwiftUI
/GRDBCombine
, and i have 2 questions (in fact, one question, it's the same topic)I have a list of TV channels with EPG datas displayed... In the iOS version, i'm refreshing the list every minute because the EPG data (time / program) can change every minutes. Is there any way to refresh the query / request for the same
View
/@ObservedObject
? And then manually send a refreshed request / datas to the view via something likeobjectWillChange.send()
?Second question (the same)... User can change the order of the channel list, or filtering the list via many options... So it's the same question, rebuilding the query with new
.filter
or other things like.order
I've tried several methods but none of them work, I'm blocked because when I do a new query and plug to
DatabasePublished(publisher)
, it loses (i think) the link with the@ObservedObject
variable of the view, which is normal.I haven't found a way to redo a query for the same
@ObservedObject
variable.On the other hand, the associations works, and that's great !!! ππ»
Thanks