Project9- GCD(Grand Central Dispatch)

  1. performSelector
//在子线程中执行
performSelector(inBackground: #selector(fetchJSON), with: nil)
//在主线程中执行
tableView.performSelector(onMainThread: #selector(UITableView.reloadData), with: nil, waitUntilDone: false)
  1. async()
//开辟一个qos队列,在其中执行
DispatchQueue.global(qos: .userInitiated).async { [unowned self] in
}
//在主线程
DispatchQueue.main.async { [unowned self] in
    self.tableView.reloadData()
}

你可能感兴趣的:(Project9- GCD(Grand Central Dispatch))