gpt4 book ai didi

swift - dataTask 错误 - "Cannot invoke ' dataTask',其参数列表类型为...”

转载 作者:行者123 更新时间:2023-11-30 12:37:23 24 4
gpt4 key购买 nike

我遇到了一些麻烦。查看下面的这部分代码:

// Create a datatask and pass in the request
let dataTask = session.dataTask(with: request, completionHandler: { (data:NSData?, response:URLResponse?, error:Error?) in

// Get a reference to the image view element of the cell
let imageView = cell.viewWithTag(1) as! UIImageView

// Create an image onject from the data and assign it into the ImageView
imageView.image = UIImage(data: data!)

})

我在第二行收到错误,这是错误:enter image description here

我该如何解决这个问题?提前致谢!

最佳答案

根据一些评论,我有了答案!我将“请求”从 NSURLRequest 更改为 URLRequest,并将代码更新为:

  // Create a datatask and pass in the request
let dataTask = session.dataTask(with: request, completionHandler: { (data, response, error) in

// Get a reference to the image view element of the cell
let imageView = cell.viewWithTag(1) as! UIImageView

// Create an image onject from the data and assign it into the ImageView
imageView.image = UIImage(data: data!)

})

关于swift - dataTask 错误 - "Cannot invoke ' dataTask',其参数列表类型为...”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42706622/

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