我最近在项目中添加了新的Pod,并更新了以前的Pod,此代码以前一直都有效,现在我收到“模棱两可的'下标'”,我一直在检查其他答案,这似乎是我的方式当前设置它是正确的方法。我不确定为什么突然之间这些代码行会被标记为错误。
databaseRef.child("following").queryOrderedByKey().observeSingleEvent(of: .value, with: { (postsSnapshot) in
let posts = postsSnapshot.value as! [String: AnyObject]
for (_, post) in posts {
for (_, postInfo) in post as! [String: AnyObject] {
if let followingID = postInfo["uid"] as? String {
for each in self.following {
if each == followingID {
guard let uid = postInfo["uid"] as! String? else {return}
guard let name = postInfo["businessName"] as! String? else {return}
guard let address = postInfo["businessStreet"] as! String? else {return}
guard let state = postInfo["businessState"] as! String? else {return}
guard let city = postInfo["businessCity"] as! String? else {return}
let data = ["uid":postInfo["uid"] as! String, "businessName":postInfo["businessName"] as! String, "businessStreet":postInfo["businessStreet"] as! String, "businessState":postInfo["businessState"] as! String, "businessCity":postInfo["businessCity"] as! String,"businessZIP":postInfo["businessZIP"] as! String, "businessPhone":postInfo["businessPhone"] as! String, "businessLatitude":postInfo["businessLatitude"] as! String, "businessLongitude":postInfo["businessLongitude"] as! String, "businessWebsite":postInfo["businessWebsite"] as! String, "facebookURL":postInfo["facebookURL"] as! String, "foursquareURL":postInfo["foursquareURL"] as! String, "googleURL":postInfo["googleURL"] as! String, "instagramURL":postInfo["instagramURL"] as! String, "snapchatURL":postInfo["snapchatURL"] as! String, "twitterURL":postInfo["twitterURL"] as! String, "yelpURL":postInfo["yelpURL"] as! String]
答案 0 :(得分:1)
问题是您使用了AnyObject
。 postInfo
被声明为AnyObject
,但随后您尝试像字典一样使用它,因此会出现错误。
如果post
是词典的字典,则声明为:
更改:
for (_, postInfo) in post as! [String: AnyObject] {
收件人:
for (_, postInfo) in post as! [String: [String: AnyObject]] {
这会将postInfo
更改为[String: AnyObject]
,而不是AnyObject
。