作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
嘿,我是 Firebase 的新手,从数据库获取数据时遇到问题,我在这一行出现错误:
let snapshotValue = snapshot.value as! [String: AnyObject]
Could not cast value of type '__NSCFString' (0x1a8e00d50) to 'NSDictionary' (0x1a8e01c78).
init(snapshot: FIRDataSnapshot) {
key = snapshot.key
let snapshotValue = snapshot.value as! [String: AnyObject]
name = snapshotValue["name"] as! String
addedByUser = snapshotValue["addedByUser"] as! String
startTime = snapshotValue["startTime"] as! Double
endPickerTime = snapshotValue["endPickerTime"] as! Double
longtitude = snapshotValue["longtitude"] as! Double
latitude = snapshotValue["latitude"] as! Double
eventImageStringUrl = snapshotValue["eventImageStringUrl"] as! String
eventId = snapshotValue["eventId"] as! String
eventDescription = snapshotValue["eventDescription"] as! String
completed = snapshotValue["completed"] as! Bool
ref = snapshot.ref
}
override func viewDidLoad() {
super.viewDidLoad()
databaseHandle = databaseRef.child("events").observe(.childAdded, with: { (snapshot) in
var newItems: [Event] = []
for item in snapshot.children {
let event = Event(snapshot: item as! FIRDataSnapshot)
newItems.append(event)
}
})
最佳答案
更改.childAdded
至.value
在 .observe
.
关于ios - Swift 3 Firebase 数据检索错误 : Could not cast value of type '__NSCFString' (0x1a8e00d50) to 'NSDictionary' (0x1a8e01c78),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44021252/
我是一名优秀的程序员,十分优秀!