I have written a query in iOS swift to retrieve data from the firebase database. But one of the values that I get in my app is different from what is stored in the database. The android equivalent works just fine. Any idea what I am doing wrong?
let usersQuery = self.mRef.child("Users").child(key)
usersQuery.observeSingleEvent(of: .value, with: {(snapshot) in
if snapshot.exists()
{
let user = snapshot.value as? NSDictionary
let active = user?["active"] as? Bool ?? false
let online = user?["online"] as? Bool ?? false
}
}, withCancel: {(error) -> Void in
})
{
"37ukAaOUHzUZWqMVwhcRF7rCbDJ2" : {
"Courses" : {
"-KfV4NbUkwkKAI2UspE5" : {
"active" : true,
"dateCreated" : "18 March 2017 08:23 AM",
"description" : "Student Description ",
"id" : "-KfV4NbUkwkKAI2UspE5",
"name" : "Programming 1",
"price" : 2800,
"special" : false
}
},
"active" : true,
"address" : "",
"admin" : false,
"fax" : "",
"id" : "37ukAaOUHzUZWqMVwhcRF7rCbDJ2",
"manager" : "Patrice",
"online" : true,
"phone" : "0812458202",
"rating" : 0,
"telephone" : "",
"website" : ""
},
"EZdEz7ZqNLMAapndjgdPx5wmnf43" : {
"Courses" : {
"-KfGdc9qKBAWSMprUg8T" : {
"active" : true,
"dateCreated" : "15 March 2017 13:07 PM",
"description" : "Used for sample descriptions",
"id" : "-KfGdc9qKBAWSMprUg8T",
"name" : "Test Course",
"price" : 500,
"special" : false
},
"-KjslUCQI48GH_PSA7ye" : {
"active" : true,
"dateCreated" : "11 May 2017 20:29 PM",
"description" : "C# introduction course",
"id" : "-KjslUCQI48GH_PSA7ye",
"name" : "C# Intro",
"price" : 250,
"special" : false
},
"-KjslefUtkVeTIqh9WQn" : {
"active" : true,
"dateCreated" : "11 May 2017 20:30 PM",
"description" : "Java introduction course",
"id" : "-KjslefUtkVeTIqh9WQn",
"name" : "Java Intro",
"price" : 250,
"special" : false
}
},
"active" : true,
"address" : "7 Henri St,",
"admin" : true,
"fax" : "",
"id" : "EZdEz7ZqNLMAapndjgdPx5wmnf43",
"manager" : "Patrice Tene",
"name" : "Grill Corner Ed",
"online" : true,
"phone" : "0812458203",
"rating" : 0,
"telephone" : "",
},
}
The result value for "active" using the above query is false for the first student only. The remaining output in correct.
Please help.