Beginning Firebase - Part 5: References | Ray Wenderlich

References are what you use to save and read data to Firebase. In this video, you'll learn how to use references in your Swift app.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/4203-beginning-firebase/lessons/5

Hey, quick question. In the previous section. you told us to write JSON to create objects, but you didn’t tell us where this JSON goes. I see in this video you’re accessing it through the database. I would like to know how the JSON got into the database. Were we supposed to do that within the Firebase terminal? If so, where?

@vegetarianzombie @bdmoakley Can you please help with this when you get a chance? Thank you - much appreciated! :]

Hey RedQueenCoder!

Basically, when you write references that get mapped to JSON inside of firebase. So you can think of references themselves as JSON objects.

So this reference actually represents the grocery items

let childRef = FIRDatabase.database().reference(withPath: "grocery-items")

That creates the equivalent of this in JSON:

{
   "grocery-items": {
   }
}

And then you set values to it. When you set a value, the JSON is transmitted to firebase for saving. I hope that helps!

btw, I’m looking forward to seeing your talk at RWDevCon!

This topic was automatically closed after 166 days. New replies are no longer allowed.

This may be too noobie of a question for this References section, but I am trying to keep up with the Grocr app while also building a separate, similar app from scratch on the side. The Grocr app does not complain at all about the print(rootRef), etc. statements, but on my mirrored project, I get a warning “Expression implicitly coerced from ‘String?’ to ‘Any’” for each of my print() statements. Is this simply a matter of Grocr app’s setting suppressing that warning or is there a deeper issue I need to explore? Uploading a screen shot as well for demonstration purposes.

59%20AM

If it helps at all, here is a comparison of the two console logs as well from when they run. Grocr-final seems clean and in control, but, armed with the same basics in AppDelete and the one ViewController I have in Paragauges, I get both warnings and more not-do-clean messages logged to the console.

comparison%20of%20two%20console%20logs%20(Grocr%20and%20Paragauges)

@bdmoakley Can you please help with this when you get a chance? Thank you - much appreciated! :]

Hey there, it’s been awhile since I last worked on this project but the warnings may have been suppressed. Typically, we don’t do that, but I used the project from an existing tutorial so that setting may be in place.

Essentially, the warning is just letting you know that you are trying to print out an optional as that key may not exist. You can do something like this:

print(rootRef.key ?? "root key has no value")

This will print out the key value, but if there is no value present, then the string “Root key has no value” will printed. You can also put those variables in an if-let block or guard statement (the video tutorial should really should do that).

I hope that helps!

1 Like

Thank you, Brian! That is perfect. I have to say everything has been working great and my mirror app is all up and running happily. I had been struggling with AWS Amplify with React the past few weeks, and in a matter of a weekend, thanks to your course, I was able to get introduced to Firebase and get my app to a deployable state.

It has been an excellent course and I will DEFINITELY provide it with five stars all the way once I’ve completed it.

BTW: I have modeled the user registration/login exactly ssd done in the course, but was wondering if there is a tutorial/project/lesson on how best/typical to provide a themed register and subsequent profile/setting (vs. just the alert style register). If you know of anty resources off the top of your head, I am all ears.

Thank you again,

  • Rob