You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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)
}
}
The text was updated successfully, but these errors were encountered:
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 funclistItemAppears
is not reached .The text was updated successfully, but these errors were encountered: