gpt4 book ai didi

swift 错误 : Ambiguous reference to member 'subscript'

转载 作者:IT王子 更新时间:2023-10-29 05:04:05 26 4
gpt4 key购买 nike

我是编码新手,选择了一些开源项目来了解这个想法。

我收到错误:

Ambiguous reference to member 'subscript'

在下面的代码中:

let pictures = ( selectedRestaurant["Pictures"] as! NSArray ) // Error

let picture = ( pictures[zoomedPhotoIndex] as! NSDictionary )

let pictureURL = picture["url"] as! String

let imageURL = NSURL(string: pictureURL)
let urlRequest = NSURLRequest(URL: imageURL!)
NSURLConnection.sendAsynchronousRequest(urlRequest, queue: NSOperationQueue.mainQueue()) {
response, data, error in
if error == nil && data != nil {

self.imageView.image = UIImage(data: data!)
self.imageView.contentMode = UIViewContentMode.ScaleAspectFit

}
}

最佳答案

只需明确指定图片的类型:

所以代替:

let pictures = selectedRestaurant["Pictures"] as! NSArray

写:

let pictures: NSArray = selectedRestaurant["Pictures"] as! NSArray

关于 swift 错误 : Ambiguous reference to member 'subscript' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34995173/

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