値テストを取得したいのですが、
エラーになります
Value of optional type 'Any?' must be unwrapped to refer to member
swift
1ref = Database.database().reference() 2 ref.child("communities").observeSingleEvent(of: .value, with: { (snapshot) in 3 // Get user value 4 let value = snapshot.value as! NSDictionary 5 6 let community = value["community1"]["title"] //エラー箇所 7 }) { (error) in 8 print(error.localizedDescription) 9 }
json
1{ 2 "communities" : { 3 "community1" : { 4 "title" : "テスト" 5 } 6 } 7}
なぜ NSDictionary を使っているのか教えて下さい。
https://www.hfoasi8fje3.work/entry/2018/05/25/191259
swift久しぶりでfirebaseも初めてだったのでこちらを参照しました
けっこう新しめの記事ですね‥。
まぁ特に理由がない限りはNSDictionaryではなくDictionaryを使った方がいいです。
承知しました!
回答1件
あなたの回答
tips
プレビュー