5 minute quickstart

iOS Quickstart

Create an account

The first thing you need to do to get started with Firebase is sign up for a free account. A brand new Firebase will automatically be created for you with its own unique URL ending in firebaseio.com. We'll use this URL to store and sync data.

Download SDK

There are multiple ways to include the Firebase SDK into your Xcode project. We can manually include the framework and its dependencies, use the Firebase Xcode templates, or include Firebase from its CocoaPod.

The templates and CocoaPod allow for a faster setup. However, if you want to include the SDK manually, continue on to the next section.

Templates

One of the easier ways to get started is to use the Xcode Project Templates. The templates allow you to skip the next section.

CocoaPods

Alternatively, if you're using CocoaPods, add the following to your Podfile and you can skip the next section.

pod 'Firebase', '>= 2.2.1'

Ruby Motion

For setting up Ruby Motion, check out our Ruby Motion installation guide.

Installing the SDK

Unzip the Firebase SDK file and drag the .framework folder to your XCode project.

Frameworks & Dependencies

Firebase depends on these other frameworks. Add them to your project:

libicucore.dylib
libc++.dylib
CFNetwork.framework
Security.framework
SystemConfiguration.framework

Classes & Categories

Firebase makes use of Objective-C classes and categories, so you'll need to add this under "other linker flags" in build settings:

-ObjC

Getting started in Xcode

Objective-C

Simply include the Firebase header in your app to get all the needed classes:

#import <Firebase/Firebase.h>

Swift

To use Swift with the iOS SDK we need to setup a bridging header. If you do not already have a bridging header, you can create one in Xcode by:

  1. If you have a Swift project, add a new Objective-C File to the project called Temp. If you have an Objective-C project, add a new Swift file called Temp.
  2. When prompted to configure an Objective-C bridging header, select "Yes."
  3. This creates the bridging header file, which ends in -Bridging-Header.h.
  4. Deleted the Temp file you created from your project.
  5. Import Firebase into your bridging header.
#import <Firebase/Firebase.h>

This is the only import you need. You will now be able to use Firebase in any of your Swift files!

Read & Write to your Firebase

Writing data

Getting data into Firebase is a cinch. We first need to create a reference to our Firebase, using our URL endpoint. Once we have a reference to your Firebase, we can write any valid JSON object to it using setValue.

// Create a reference to a Firebase location
Firebase *myRootRef = [[Firebase alloc] initWithUrl:@"https://myapp.firebasio-demo.com/"];
// Write data to Firebase
[myRootRef setValue:@"Do you have data? You'll love Firebase."];
// Create a reference to a Firebase location
var myRootRef = Firebase(url:"https://<your-firebase>.firebaseio.com/")
// Write data to Firebase
myRootRef.setValue("Do you have data? You'll love Firebase.")

Reading data

Firebase will stream data in realtime to any client that is listening. To setup a listener we need to call the observeEventType method. We will use the FEventTypeValue to listen for all changes. Then we'll add a block that returns a FDataSnapshot object that contains our data.

// Read data and react to changes
[myRootRef observeEventType:FEventTypeValue withBlock:^(FDataSnapshot *snapshot) {
  NSLog(@"%@ -> %@", snapshot.key, snapshot.value);
}];
// Read data and react to changes
myRootRef.observeEventType(.Value, withBlock: {
  snapshot in
  println("\(snapshot.key) -> \(snapshot.value)")
})
Call value on the FDataSnapshot returned from the callback to access the data.

In the example above, the value event will fire once for the initial state of the data, and then again every time the value of that data changes. You can learn more about the various event types and how to handle event data in our documentation on reading data.

Add Authentication

Firebase provides full support for authenticating users. For common login options, such as email and password, Facebook, Twitter and Google, checkout out guide on User Authentication provides a quick way to get started. More advanced users may want to use custom login for complete control over user management and authentication.

Use Firebase to manage your authentication

Secure Your Firebase

Use our powerful expression-based Security and Firebase Rules to control access to your data and validate input:

{
  ".read": true,
  ".write": "auth.uid === 'admin'",
  ".validate": "newData.isString() && newData.val().length < 500"
}

Firebase enforces your Security and Firebase Rules consistently whenever data is accessed. The rules language is designed to be both powerful and flexible, so that you can maintain fine-grained control over your application's data.

What's Next?