Reputation: 1
I'm trying to get data out of a firebase database if the addedByUser = a value stored in the application.
With what I currently have, nothing is appearing in the table.
The firebase database looks like this:
workout1 "name" "addedByUser"
My code looks like this:
workout3Ref.observeEventType(.Value, withBlock: { snapshot in
var newWorkout = [Workout1Info]()
for item in snapshot.children {
let createdBy = snapshot.value["addedByUser"] as? String
if createdBy == Username.sharedInstance.userDetail {
let workoutItem = Workout1Info(snapshot: item as! FDataSnapshot)
newWorkout.append(workoutItem)
}
}
self.workouts = newWorkout
self.tableView.reloadData()
})
When I get data normally without comparing if the addedByUser it normally works. Does anyone know why it isn't working?
Thanks for the help
Upvotes: 0
Views: 160
Reputation: 352
String
createdBy
with Username.sharedInstance.userDetail
check your property Username.sharedInstance.userDetail
also should be of String
type.Upvotes: 0
Reputation: 35648
Here's my guess based on a super vague question with some coding issues:
The createdBy is the users name or uid as a string.
The Username.sharedInstance.userDetail is an object (of some kind)
So you are comparing a String to an object that isn't a string, and that won't work.
Also, if the node you are query-ing is the /workout1 node, then you should probably name your reference workout1Ref instead of workout3Ref. That may help keep things straight in code.
Upvotes: 1