Group Group Group Group Group Group Group Group Group Forums

Firebase Tutorial: Getting Started

In this Firebase tutorial, you'll learn about the fundamentals, including saving data, real-time sync, authentication, user status, and offline support.

This is a companion discussion topic for the original entry at
1 Like

Wonderful job!

Hope you upload some tutorials on multi-media processing about Firebase in swift.
Such as image/video upload/download, which is essential for a good app.

Nice tutorial David, very nice way to get started with Firebase. Would you have or would you know where I could find a very similar tutorial for Android?

Since you guys cover iOS and Android, I think it would be very beneficial to the community if you could provide your tutorials in SWIFT and Java (Android).


Check out udacity. They have a full on FREE andorid-firebase course on a Shopping list app which is a lot more involved than this.

When “Observing Authentication State” we just check if the authData is nil, the thing is that it already has data every time the app starts, so every time I re-build it automatically goes to the grocery list view, shouldn’t the app always ask for credentials? we are not saving any token or credentials on the device, so if authData is retrieved from Firebase at start, how does the Firebase know which user is asking for authentication? or am I missing something?

HI there!

This tutorial is exactly what I need, but I’m getting errors and warnings when trying to compile the starter project. Am I the only one or is it because of the latest updates to OS X and Xcode (I have Version 7.3 (7D175))? I’m a bit of a newbie here so bear with me.

There are 3 errors, all of which have the message:
Downcast from ‘UITableViewCell?’ to ‘UITableViewCell’ only unwraps optionals; did you mean to use ‘!’?

There are also 8 warnings but I didn’t really pay attention to them…

Any help would be greatly appreciated :smiley:

Happy coding!

I think this is because the tutorial was written before Swift 2.0 was implemented within Xcode, so, just change the “?” for “!” which is what I did and it worked correctly

I’m getting the following error “thread 1 exc_bad_instruction (code=exc_i386_invop subcode=0x0)” at line 44 in the GroceryItem struct file “name = snapshot.value[“name”] as! String” it says in the console that “fatal error: unexpectedly found nil while unwrapping an Optional value” any ideas? I just downloaded the complete project and it is not working neither

This didn’t seem to do the full trick for me. See my response below.


These are the changes I made for the errors from Swift 1 to Swift 2 and also additional notes on the tutorial.

In GroceryListTableViewController.swift
For the warning in line 45, change the selector of userCountBarButtonItem from
userCountBarButtonItem = UIBarButtonItem(title: “1”, style: UIBarButtonItemStyle.Plain, target: self, action: Selector(“userCountButtonDidTouch”))
userCountBarButtonItem = UIBarButtonItem(title: “1”, style: UIBarButtonItemStyle.Plain, target: self, action: #selector(GroceryListTableViewController.userCountButtonDidTouch))

For the error in line 68, change the cell declaration from
let cell = tableView.dequeueReusableCellWithIdentifier(“ItemCell”) as! UITableViewCell
let cell = tableView.dequeueReusableCellWithIdentifier(“ItemCell”, forIndexPath: indexPath)

For the error in line 126 change the textField declaration in line 126 from
let textField = alert.textFields![0] as! UITextField
let textField = alert.textFields![0]

For the error in the following line (127) add ! in the groceryItem declaration:
let groceryItem = GroceryItem(name: textField.text, addedByUser:, completed: false)
let groceryItem = GroceryItem(name: textField.text!, addedByUser:, completed: false)

In OnlineUsersTableViewController.swift
Change cell declaration in line 46 to clear the error from Swift 1 to Swift 2 from
let cell = tableView.dequeueReusableCellWithIdentifier(UserCell) as! UITableViewCell
let cell = tableView.dequeueReusableCellWithIdentifier(UserCell, forIndexPath: indexPath)

Additionally, In LoginViewController.swift
I changed the alert in line 48 from var to let since it does seem to only have one value.
I also changed the emailField and passwordField declarations by removing “as! UITextField” so that it looks like this
let emailField = alert.textFields![0]
let passwordField = alert.textFields![1]
but I don’t recall if this was absolutely necessary.

As for the tutorial itself, I have some notes:
In section Displaying a List of Online Users

  • The tutorial says to change viewDidAppear but there is no viewDidAppear code, do we add it or was viewDidLoad the intended function? (both seem to work)
  • In OnlineUsersTableViewController.swift there is no reference to usersRef like in GroceryListTableViewController.swift, yet the tutorial assumes you already do or you already imported it. So, does it need to be added in the same way we did in the other file or should it be imported? (I just added it)
  • For the last piece of code to be added in this section, change enumerate(self.currentUsers) and instead use self.currentUsers.enumerate() as the former gives error (I guess due to the Swift 2 changes).
  • The tutorial says “Using a bit of trickery, it’s possible to add a user to Online…” if this sounded a bit ambiguous as there is no explicit mention of what that trickery means, the actual trick is to press the + button in the online data tree

Lastly, in the section Enabling Offline
The code for AppDelegate.swift that we’re supposed to add is already added there in the starter project.

Hope this helps
Happy coding!

1 Like

Thanks, this removed most errors. I still can’t compile though, I get a “linker command failed with exit code 1” error. Anyone know what I can do about this?

edit: never mind, I wasn’t working in the workspace :sweat_smile:


I had the same problem and the way I solved it was making the totally installation of the Firebase pod from terminal.

-First, Xcode must be closed.

-Make all the installation of Firebase pod from Terminal:

cd your-xcode-project-directory
pod init
open -a Xcode Podfile

-Write the following in your Podfile

platform :ios, “8.0”
target ‘the name of your Xcode-project’ do
pod ‘Firebase’, ‘>= 2.5.0’

-The run the following from Terminal to install pod

pod install

-Once time you have finished with the installation of Firebase launch Xcode from Terminal:

open your-project.xcworkspace

Remember: The key here is that after the installation of Firebase Pod you have to launch your project from terminal and not from Xcode.

I hope it help you


The tutorial works great (with some minor fixes from outdated syntax) and builds fine on the simulator, however, if you want to test it out on the iPhone make sure you do the following:

  • Go to Build Settings

  • Underneath Build Settings scroll down to Build Options

  • In Build Options, switch the Enable Bitcode setting to No

That should allow you to build and test the app on your iPhone,

I have a minor query about this tutorial; how come there’s no way for users to sign-out? While the sign up and login function work fine, it’s very difficult to test without having to delete and re-install the app because there’s absolutely no way for new users to sign-up as the build automatically segues directly to the Table View where the grocery list is.

The only way I have been able to get back into the LoginViewController to use the Sign Up function is if I build the app on different iOS Simulators (eg: iPhone 4s, 5, 5s etc…). :thinking:

That’s expected behavior, when users sign in, they get their user stored in the app so they don’t need to sign in again.
What I did to complete the features and be able to change users is a Sign out button in the first screen. What this does is simply a Exit segue to the LoginViewController, which calls ref.unauth() and Firebase.goOffline() so the user gets erased and the online monitoring consider the user offline on the other running apps.

Check my answer below about sign out functionality

Trying to do this tutorial and I got to the first implementation of the first call to save an item and I get this:

2016-05-09 02:28:35.792 Grocr[26579:1592969] _BSMachError: (os/kern) invalid capability (20)
2016-05-09 02:28:35.792 Grocr[26579:1593630] _BSMachError: (os/kern) invalid name (15)

Anyone have any ideas why I am getting this?

I tried all the usual things - Google, removing line by line, adding line by line back… I get nothing!

Would love to do this tutorial for Firebase but it doesn’t seem to work anymore.


I have the same problem.

Have you find a solution?

Is there an updated version of this Tutorial since Swift 2.0 was released and Firebase is now powered by Google?

[Firebase] setValue: or removeValue: at /grocery-items/test failed: permission_denied

I can’t even add an Item, just added the ref line, and updated the save function and fixed the errors… Is there a step I’m missing?

Anyway you can update this tutorial with the new firebase release? Thanks!