Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example and readMe is not clear! #1

Open
Dave181295 opened this issue May 6, 2022 · 0 comments
Open

Example and readMe is not clear! #1

Dave181295 opened this issue May 6, 2022 · 0 comments

Comments

@Dave181295
Copy link

Dave181295 commented May 6, 2022

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)
                
            }
            
        }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant