-
Notifications
You must be signed in to change notification settings - Fork 6
Open
Description
Please make a better example, things are not clear, you init the array first with populated data, then you append it with the fetched one from an API, the first part is not possible, do I need to fetch all the data first? because when trying your code with an empty array (first time its empty) , nothing happens, as the condition isLast in the func listItemAppears is not reached .
@State var historyMessages = [Message]()
@State var isFetching = false
@State private var page: Int = 0
private let pageSize: Int = 25
//Arr is empty here , condition wont met
if historyMessages.isLastItem(item) {
self.page += 1
self.getMoreItems(forPage: self.page, pageSize: self.pageSize) { moreItems in
historyMessages.append(contentsOf: moreItems)
isFetching = false
}
}
func getMoreItems(
forPage page: Int,
pageSize: Int, completion: @escaping ([Message]) -> () ) {
let maximum = ((page * pageSize) + pageSize) - 1
let maxCount = historyMessages.count - maximum
phrasesModel.dbManager.retrieveAllMessage { messages in
guard let fetchedMessages = messages else {
return
}
var copyArr = fetchedMessages
for i in historyMessages.count...maxCount {
copyArr.remove(at: i)
}
completion(copyArr)
}
}
Metadata
Metadata
Assignees
Labels
No labels