gpt4 book ai didi

ios - Swift 3 Firebase 数据检索错误 : Could not cast value of type '__NSCFString' (0x1a8e00d50) to 'NSDictionary' (0x1a8e01c78)

转载 作者:行者123 更新时间:2023-12-01 19:53:38 28 4
gpt4 key购买 nike

嘿,我是 Firebase 的新手,从数据库获取数据时遇到问题,我在这一行出现错误:

      let snapshotValue = snapshot.value as! [String: AnyObject]

你能帮我解决这个问题吗?

错误提示:
Could not cast value of type '__NSCFString' (0x1a8e00d50) to 'NSDictionary' (0x1a8e01c78).

事件 Controller :
  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)
}


})

数据库方案:

enter image description here

最佳答案

更改.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/

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