I am trying to load an array of arrays with Firebase and would appreciate any help on how to do so. Thanks! Picture is of database.
1 Answer
You need to observe defense then inside the callback
self.ref.child("defense").observeSingleEvent(of: .value, with: { snap in
let res = snap.value as! [String:[String:Int]]
let all = Array(res.values).map { Array($0.values) } // [[-1,-1,-1],[...]]
})
6 Comments
Tyler Rutt
its giving me 'Could not cast value of type '__NSArrayM' (0x1f4932630) to 'NSDictionary' (0x1f49335f8).'
Shehata Gamal
tell me what this gives
print(type(of:snap.value))Tyler Rutt
its a Optional<Any>
Shehata Gamal
and this
let res = snap.value as! [[String:Any]]Tyler Rutt
it says res is a ([[String: Any]]). The program stops and shows the varbiable values in the feed. No error msg just program breaks.
|
