Swift 3没有下标错误
在我转换到swift 3期间,在尝试从我的分析数据库中定义标签的文本时遇到错误。这里就是我定义我的手机验证码:Swift 3没有下标错误
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "ExpandCell", for: indexPath) as! ExpandingCollectionViewCell
let object = self.imageFilesArray[(indexPath as NSIndexPath).row]
cell.nameLabel.text = String(describing: object["name"]).uppercased()
return cell
就行了“cell.nameLabel.text ......”我得到一个错误,说明“中键入任何没有标成员。”我搜遍了各地,发现有类似的问题,但没有人能够帮助我。有没有人有什么建议?
编辑:这里是我定义imageFilesArray代码:
let query = PFQuery(className: "Events")
query.order(byAscending: "dateString")
query.findObjectsInBackground{
(objects, error) -> Void in
if error == nil {
self.imageFilesArray = objects! as NSArray
您是否尝试过铸造的对象变量应该是什么尝试访问它之前?
let object = self.imageFilesArray[(indexPath as NSIndexPath).row] as [String:String]
其中[String:String]是您的对象试图成为的任何对象。
试试这个
cell.nameLabel.text = String(describing: (object as AnyObject)["name"]).uppercased()
那没有做到这一点,它现在陈述'模糊使用下标' – user3255746
什么是imageFilesArray的声明? 你可以将它设置为'var imageFilesArray:[PFObject] = []' 并改变'self.imageFilesArray = objects! as NSArray' to'self.imageFilesArray = objects as! [PFObject]'那么你应该可以使用'object [“name”]'而不需要任何强制转换。 – Sam
无关你的问题,但并不需要投给NSIndexPath:http://stackoverflow.com/questions/39631905/nsindexpath-and-indexpath-in-swift-3- 0。 –
什么是self.imageFilesArray数组? –
他们是来自解析的PFObjects – user3255746