我試圖將緊急數據解析爲緊急結構,但它從來沒有定性條件,並進入其他case.Here是我的代碼和結構。我寫了一些woring在第一行。正在解析swift3中的問題
if let emergencyDict = snapshotValue["emergency"] as? [String:[String:Any]]{
for (emerId, emerData) in emergencyDict {
let emer = Emergency.init(emergency: emerData as NSDictionary)
emergency.append(emer)
}
}
else{
let emer = Emergency.init(emerg: "" as AnyObject)
emergency.append(emer)
}
struct Emergency{
var emer_id: String
var emer_name: String
var emer_phoneNo: String
init(emergency: NSDictionary) {
if emergency.object(forKey: "id") != nil {
emer_id = emergency.object(forKey: "id") as! String
}
else{
emer_id = ""
}
}
}
我試過這個,但它也沒有奏效。 –
當我試圖打印 打印(snapshotValue [ 「緊急」] ?? AnyObject.self) 則O/P爲: ( 「」, { ID = 1; 名稱=父親; PHONENO = 01828020209; },{ ID = 2; 名稱=母親; PHONENO = 12345678; } ) –
'snapshotValue [ 「緊急」]'是一個數組正確? –