我有一个使用旧的Swift代码开发的应用程序。现在,我将其更新为最新的Swift语法。在进行更新时,我发现调度队列中存在困难,这里给出了两个警告,因为在iOS 8中不推荐使用global(priority),在iOS 8中不推荐使用背景。
DispatchQueue.global(priority: DispatchQueue.GlobalQueuePriority.background).async(execute: { [weak self] in //Getting warning in this line
if let strongSelf = self {
strongSelf.populateOutBoundContacts()
strongSelf.lookForContactsToPresent()
}
})
Run Code Online (Sandbox Code Playgroud) 我有 api 它返回 json 响应( https://pixabay.com/api/?key=10961259-e4e939648ed5abb6879f1fbbc&q=yellow+flowers&image_type=photo)
\n\n我想访问参数(webformatURL、标签我想从响应中我发出了 URL 会话请求并获取数据如下所示。我如何从 swift 的响应中查询和访问这些参数。我是编程新手,请快速建议我。
\n\n//Mark:- Method to fetch data from the url\nfunc getDataFromUrl(){\n let url = URL(string: "https://pixabay.com/api/?key=10961259-e4e939648ed5abb6879f1fbbc&q=yellow+flowers&image_type=photo")\n let request = NSMutableURLRequest(url: url!)\n request.httpMethod = "GET"\n let session = URLSession.shared\n let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in\n if error == nil\n {\n do\n {\n let respDict = try JSONSerialization.jsonObject(with: data!, options: JSONSerialization.ReadingOptions.allowFragments) \n\n print("Some Data: \\(respDict)")\n\n }\n catch let error2 …Run Code Online (Sandbox Code Playgroud)