Skip to content

Instantly share code, notes, and snippets.

@daoseng33
Created September 10, 2018 16:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daoseng33/f762d36ea09ddf1750096497a892371a to your computer and use it in GitHub Desktop.
Save daoseng33/f762d36ea09ddf1750096497a892371a to your computer and use it in GitHub Desktop.
DispatchQueue.global(qos: .background).async { // 背景線程
let initialIndex = self.datas.count // 原本已有的 20 筆資料
var indexPaths: [IndexPath] = [] // 將要加入新項目的懵懂 array
for index in 0..<newPackOfDatas.count { // 將 indexPaths 加入新的 20 筆資料
let indexPath = IndexPath(item: initialIndex + index, section: 0) // 注意起始位置是 20(initialIndex 為還沒更新前的資料 count)
indexPaths.append(indexPath)
}
self.datas += newPackOfDatas // 將新的資料加入 datas
DispatchQueue.main.async { // 切回主線程
self.tableView.insertItems(at: indexPaths) // 安心的插入吧(?)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment