sendAsynchronousRequest was deprecated in iOS 9, How to alter code to fix

后端 未结 10 2172
长发绾君心
长发绾君心 2020-12-04 15:48

Below is my code I am getting the issue with:

func parseFeedForRequest(request: NSURLRequest, callback: (feed: RSSFeed?, error: NSError?) -> Void)
{
    N         


        
10条回答
  •  春和景丽
    2020-12-04 16:05

    Swift 4.2

    This worked for me:

    func loadImageFromURL(URL: NSURL) {
        let request = URLRequest(url: URL as URL)
        let task = URLSession.shared.dataTask(with: request) { (data, response, error) in
            if let imageData = data {
                DispatchQueue.main.async {
                    self.imageView.image = UIImage(data: imageData)
                }
            }
        }
        task.resume()
    }
    

    I had to add "DispatchQueue.main.async { }" because I had a runtime warning, since only the main thread is supposed to modify UI elements.

提交回复
热议问题