答案 0 :(得分:2)
将项目转换为FIRDataSnapshot并获取值。
let s = textField?.text!.lowercased()
DataService.ds.MSGS_DB_REF_KEY1.queryOrdered(byChild: "livelli").observe(.value, with: { snapshot in
for item in snapshot.children{
let itemSnap = item as! FIRDataSnapshot
for child in itemSnap.children {
childSnap = child as! FIRDataSnapshot
if let firebaseVal = childSnap.childSnapshot(forPath: "text").value as? String {
if s?.contains(firebaseVal.lowercased()){
}
}
}
}
})
答案 1 :(得分:2)
您需要从FIRDataSnapshot中获取值:
for item in snapshot.children{
if let itemValue = (item as? FIRDataSnapshot).value as? String, let s = s, s.contains(itemValue){
}
}
此外,如果您不需要,请不要强行打开包装。安全地打开它们,以便在将来发生变化时不会有崩溃的风险。