我必须从Firebase数据库检索此数据并将其显示在UITableView中。我创建了一个演习类来存储对象,然后,我必须将这些演习对象存储在演习类型的ExercisesArray中。我能够检索值,但不能存储在Exercise对象中。我怎样才能做到这一点?请帮忙。
运动课-
class Exercise: NSObject {
var name: String?
var bodyPart: String?
var sets: String?
var exerciseDescription: String?
var image: String?
init(name: String?, bodyPart: String?, sets: String?, exerciseDescription: String?, image: String? ) {
self.name = name
self.bodyPart = bodyPart
self.sets = sets
self.exerciseDescription = exerciseDescription
self.image = image
}
}
检索方法
class ExerciseList{
func getExerciseDataFromDatabase(bodyPart: String){
//var exercises: NSDictionary = [:]
dbRef?.child("exercises/bodyParts").child(bodyPart).observeSingleEvent(of: .value, with: { (snapshot) in
if let values = snapshot.value as? [String : AnyObject]{
print(values)
}
})
}
}