在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
遇到一个编译报错: 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) |
请发表评论