I am using a FetchRequest in a chat app and want to set the fetchLimit dynamically. First I want to load 50 messages, then an additional number when the user scrolls to the top of the chat message list.
I am using the following code:
@FetchRequest private var messages: FetchedResults<Message>
private var predicate: NSPredicate
private var fetchLimit = 50
init(chatID: String) {
self.predicate = NSPredicate(format: "chatID_ = %@", chatID)
self._messages = FetchRequest(
entity: Message.entity(),
sortDescriptors: [
NSSortDescriptor(keyPath: \Message.createdAt_, ascending: true),
],
predicate: self.predicate
)
}
How can I incorporate a fetchLimit into this which I can change dynamically?