我是新来的编码,并拿起一些开源项目来获得这个想法.希望你们可以帮助我解决这个问题
let pictures = ( selectedRestaurant["Pictures"] as! NSArray ) //Here's where i get the 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 } } } }
只需明确指定什么是图片的类型:
原文链接:https://www.f2er.com/swift/319777.html所以代替:
let pictures = selectedRestaurant["Pictures"] as! NSArray
写:
let pictures: NSArray = selectedRestaurant["Pictures"] as! NSArray