gpt4 book ai didi

ios - 对成员数据任务的引用不明确(: completionHandler:)

转载 作者:行者123 更新时间:2023-11-29 00:06:19 26 4
gpt4 key购买 nike

为什么我的完成处理程序出现问题,我该如何解决?

func loadImageusingCacheWithUrlString(urlString: String) {

self.image = nil
if let cachedImage = imageCache.object(forKey: urlString as AnyObject) as? UIImage {
self.image = cachedImage
return
}

let url = NSURL(string : urlString)

URLSession.shared.dataTask(with: url!,
completionHandler: { (data, response, error) in
if error != nil {
print(error!)
return
}
DispatchQueue.main.async(execute: {
if let currImage = UIImage(data: data) {
imageCache.setObject(currImage, forKey: urlString)
self.image = currImage
}

//cell.imageView?.image = UIImage(data: data)
})

}).resume()

}

最佳答案

使用这个

let url = URL(string : urlString)

您也可能会收到错误消息“可选类型‘数据’的值?”没有展开”,所以你应该这样写:

if let currImage = UIImage(data: data!) {
imageCache.setObject(currImage, forKey: urlString)
self.image = currImage
}

关于ios - 对成员数据任务的引用不明确(: completionHandler:),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47966304/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com