一、Thread
import UIKit class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() let operation = BlockOperation(block: { [weak self] in self?.downloadImage() return }) //创建一个NSOperationQueue实例并添加operation let queue = OperationQueue() queue.addOperation(operation) } //定义一个下载图片的方法,线程调用 func downloadImage(){ let imageUrl = "http://hangge.com/blog/images/logo.png" let data = try! Data(contentsOf: URL(string: imageUrl)!) print("该方法被线程2调用") print(data.count) } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() } }