iPages
iPages copied to clipboard
Observable object with iPages
So, first of all, I'm a total SwiftUI beginner so bare with me.
I'm working on my first app in which I would like a page view controller that allows me to swipe between views. In my app I'm fetching calendar events which I'm accessing in my views through an observable object. The problem is that when I'm trying to access my observed object in iPages, the array is empty and I can't understand why. Here is a simplified example:
class EventsRepository: ObservableObject {
static let shared = EventsRepository()
// Code
@Published var events: [EKEvent]?
// Code
let events = self.eventStore.events(matching: predicate)
}
import iPages
struct ContentView: View {
@ObservedObject var eventsRepository = EventsRepository.shared
@State private var currentPage = 0
var body: some View {
Text(String(describing: eventsRepository.events)) // This is **not** empty
iPages(selection: $currentPage) {
Text(String(describing: eventsRepository.events)) // This **is** nil
}
}
}
If this is not a problem with iPages I would really appreciate if you could try to explain to me what I'm doing wrong.
Thanks!
This project is dead since November.
It's true we've been crazy busy with work.
I'll try to play w/ your code & give this issue a more proper read through this weekend!
@AlexFine Fantastic, thank you!
@AlexFine I understand that you are busy but do you have any updates on this? Let me know if you need more details or if you want me to demo my specific case for you.
I would really like to get this working since iPages by far is the smoothest pager I've tested.
Thanks!
Okay I played around with your code & I might need some more info here. Specifically, it seems like you're redeclaring events
in the "EventsRepository", can you post another code snippet or something to showcase the difference between these?
Another theory I have here is that this bug could have to do with how ObservedObject
works, and the fact that it does not publish changes from the child properties if the parent property is observed. I can't be certain however without seeing how your self.eventStore.events(matching: predicate)
function propagates changes.
For more on the ObservableObject
bug, checkout this page: https://joinontap.com/observableobject, specifically the section on "Manually triggering objectWillChange". I have a feeling that'll help.
Actually see my comment on this issue: https://github.com/benjaminsage/iPages/issues/19
It appears State
data is not being properly passed into iPages
. Will investigate why this is happening.
I have a feeling the same bug is causing both issues