标签:error: UNC with url 一个 hot ssr fun swift
遇到一个编译报错:
Escaping closure captures non-escaping parameter ‘onCompletion‘
代码如下:
func fetchRecentPhotos(completion: (PhotosResult) -> Void) { let url = recentPhotosURL() let request = URLRequest(url: url as URL) let task = session.dataTask(with: request) { (data, response, error) -> Void in let result = self.processRecentPhotosRequest(data: data as NSData?, error: error as NSError?) completion(result) } task.resume() }
这是由于completion导致的,默认闭包completion是@nonescaping的,只需要声明成@escaping即可。
func fetchRecentPhotos(completion: @escaping (PhotosResult) -> Void)
Swift: Escaping closure captures non-escaping parameter 'onCompletion'
标签:error: UNC with url 一个 hot ssr fun swift
原文地址:https://www.cnblogs.com/fengyaoyao/p/12830168.html