Originally created by @woodyjhonson on GitHub (Apr 21, 2023).
Hello everyone, I'm dealing with observers and I just can't figure out how to make pagination? Below is a sample code, thanks in advance for your responses.
private var todosFetchOffset: Int = 0
private lazy var todoPublisher = CoreStoreDefaults.dataStack.publishList(
From<Todo>()
.orderBy(.descending(\.$updatedAt))
.tweak { [weak self] in
$0.fetchOffset = self?.todosFetchOffset ?? 0
$0.fetchLimit = 5
}
)
override func viewDidLoad() {
dataSource.apply(todoPublisher.snapshot)
todosFetchOffset = todoPublisher.snapshot.numberOfItems
todoPublisher.addObserver(self) { [weak self] listPublisher in
guard let self else { return }
let snapshot: ListSnapshot<Todo> = listPublisher.snapshot
self.todosFetchOffset = listPublisher.snapshot.numberOfItems
self.dataSource.apply(snapshot)
}
}
`
Originally created by @woodyjhonson on GitHub (Apr 21, 2023).
Hello everyone, I'm dealing with observers and I just can't figure out how to make pagination? Below is a sample code, thanks in advance for your responses.
[https://github.com/woodyjhonson/corestore_todolist](https://github.com/woodyjhonson/corestore_todolist)
`
private var todosFetchOffset: Int = 0
private lazy var todoPublisher = CoreStoreDefaults.dataStack.publishList(
From<Todo>()
.orderBy(.descending(\.$updatedAt))
.tweak { [weak self] in
$0.fetchOffset = self?.todosFetchOffset ?? 0
$0.fetchLimit = 5
}
)
override func viewDidLoad() {
dataSource.apply(todoPublisher.snapshot)
todosFetchOffset = todoPublisher.snapshot.numberOfItems
todoPublisher.addObserver(self) { [weak self] listPublisher in
guard let self else { return }
let snapshot: ListSnapshot<Todo> = listPublisher.snapshot
self.todosFetchOffset = listPublisher.snapshot.numberOfItems
self.dataSource.apply(snapshot)
}
}
`
Unfortunately, NSFetchedResultsController (which is what ListPublishers run on internally) does not honor the fetchLimit and fetchOffset of the fetch request. You can try this again if it works on recent iOS versions, but historically it is known to be ignored.
In cases like yours, we just fetch the whole list and manage the indexes/counts and applying them to ListPublisher.snapshot
@JohnEstropia commented on GitHub (Apr 24, 2023):
Unfortunately, `NSFetchedResultsController` (which is what `ListPublisher`s run on internally) does not honor the `fetchLimit` and `fetchOffset` of the fetch request. You can try this again if it works on recent iOS versions, but historically it is known to be ignored.
In cases like yours, we just fetch the whole list and manage the indexes/counts and applying them to `ListPublisher.snapshot`
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Originally created by @woodyjhonson on GitHub (Apr 21, 2023).
Hello everyone, I'm dealing with observers and I just can't figure out how to make pagination? Below is a sample code, thanks in advance for your responses.
https://github.com/woodyjhonson/corestore_todolist
`
`
@JohnEstropia commented on GitHub (Apr 24, 2023):
Unfortunately,
NSFetchedResultsController(which is whatListPublishers run on internally) does not honor thefetchLimitandfetchOffsetof the fetch request. You can try this again if it works on recent iOS versions, but historically it is known to be ignored.In cases like yours, we just fetch the whole list and manage the indexes/counts and applying them to
ListPublisher.snapshot