I want to insert an array at the beginning of another array. How can I do that in Swift?
Basically, when the user scrolls to top, I get the data from the server and want to present the new data at the top, not at the bottom.
Here is my code:
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
if indexPath.row == 0 { // user reached the top
if (self.loadMore == true) {
self.page += 1
self.getUserData(Page:self.page)
}
}
}
func getUserData(Page:Int) {
DataService().getData(page:Page) { data, error, errorDic in
if error != nil {
//oops
return
}
if (self.loadMore == true) {
self.data += data!
}
self.tableView.reloadData()
}
}