次のJSONツリーの配列の値を取得したいです(写真のfuda1L
等)。私はsnapshot
を引数にとってUserInfoClass
という名のClassでその配列を[String]
で取得しようとしましたが、オプショナルnilが出てきてしまいました。解決法をご教示頂きたいです。
Swift
1 func retriveData(){ 2 3 refUserInfo = Database.database().reference().child("users") 4 refUserInfo.observe(.value) { (snapshot) in 5 let info = UserInfoClass.init(snapshot: snapshot) 6 //userInfo is [UserInfoClass] 7 self.userInfo.append(info!) 8 self.InfoTableView.reloadData() 9 10 } 11 }
以下が 'UserInfoClass'
です。
init? (snapshot: DataSnapshot) { guard let applyDict = snapshot.childSnapshot(forPath: "ApplyInfo").value as? [String: Any] else {return nil } guard let peopleNum = applyDict["peopleNum"] as? Int else { return nil } print("peopleNum: (peopleNum)\n") guard let payType = applyDict["payType"] as? [String] else { return nil } print("payType:(payType)\n") guard let receiveType = applyDict["receiveType"] as? [String] else { return nil } print("receiveType: (receiveType)\n") guard let furigana2 = applyDict["furigana2"] as? [String] else { return nil } print("furigana2: (furigana2)") guard let prayman2 = applyDict["prayman2"] as? [String] else { return nil } print("prayman2: (prayman2)\n") guard let furigana1 = applyDict["furigana1"] as? [String] else { return nil } print("furigana1:(furigana1)\n") guard let prayman1 = applyDict["prayman1"] as? [String] else { return nil } print("prayman1:(prayman1)\n") guard let prayType2 = applyDict["prayType2"] as? [String] else { return nil } print("prayType2:(prayType2)\n") guard let prayType1 = applyDict["prayType1"] as? [String] else { return nil } print("prayType1:(prayType1)") guard let moneySum = applyDict["moneySum"] as? [Int] else { return nil } print("moneySum:(moneySum)\n") guard let fuda1Small = applyDict["fuda1S"] as? [String] else {return nil} guard let fuda1Mid = applyDict["fuda1M"] as? [String] else {return nil} guard let fuda1Large = applyDict["fuda1L"] as? [String] else {return nil} guard let fuda3Small = applyDict["fuda3S"] as? [String] else {return nil} guard let fuda3Mid = applyDict["fuda3M"] as? [String] else {return nil} guard let fuda3Large = applyDict["fuda3L"] as? [String] else {return nil} guard let fuda5Small = applyDict["fuda5S"] as? [String] else {return nil} guard let fuda5Mid = applyDict["fuda5M"] as? [String] else {return nil} guard let fuda5Large = applyDict["fuda5L"] as? [String] else {return nil}
あなたの回答
tips
プレビュー