MHDev MHDev - 1 year ago 63
Swift Question

How can I save this object model data to Firebase

I have a model for a routine like the following:

struct Routine {
var routineName: String!
var routineExercisesAndSets: [String:Int]!

And a
where I collect data before creating a new instance of that model, which once created looks like:

var routine = Routine()

//values are assigned to the routine here and then when printed looks like below

(routineName: All Over,
routineExercisesAndSets: ["Bent Over Row": 3, "Barbell Curl": 3, "Bench Press (Flat)": 4])

How could I save this into Firebase so that it fits my data structure

"routines": {
"users unique identifier": {
"routine unique identifier": {
"routine_name": "routine name",
"routine_create_date": "routine created date",
"exercises": {
"exercise name": {
"Sets": "number of sets",
"rest between sets": "timer duration"

user unique identifier
will be the current logged in users uid and
routine unique identifier
will be an autoId, but how can I work through the model to push data to Firebase the same as the model?

Answer Source

If your user is authenticated try this:-

        "routine_Name" : "All Over",
        "routine_create_date": "routine created date",
        "exercises": [
            "exercise name": [
                "Sets": "number of sets",
                "rest between sets": "timer duration"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download