Welcome to the Firebase App Quality codelab. In this codelab, you'll learn how to use the Firebase platform to create iOS applications. You will implement a simple app, monitor its performance, and report a crash using Firebase.

This codelab is also available in Objective-C.

What you'll learn

What you'll need

How will you use this tutorial?

Read it through only Read it and complete the exercises

How would rate your experience with building iOS apps?

Novice Intermediate Proficient

Clone the GitHub repository from the command line.

$ git clone https://github.com/firebase/appquality-codelab-ios

To build the starter app:

  1. In a terminal window, navigate to the android_studio_folder.pngios-starter/swift-starter directory from your sample code download
  2. Run pod install
  3. Open the AppQualitySwift.xcworkspace file to open the project in Xcode.
  4. Click the Run button.

You should see the App Quality home screen appear after a few seconds. The UI should appear. However, at this point you can't track specific performance or get crash reports.

Create project

From Firebase console select Add Project.

Call the project AppQuality, then click on Create Project.

Screenshot from 2015-11-06 14:13:39.png

Connect your iOS app

  1. From the Project Overview screen of your new project, click Add Firebase to your iOS app.
  2. Enter the bundle ID, as "com.google.firebase.codelab.AppQualitySwift".
  3. Enter the App Store id as "123456".
  4. Click Register App.

Add GoogleService-Info.plist file to your app

On the second screen click Download GoogleService-Info.plist to download a configuration file that contains all the necessary Firebase metadata for your app. Copy that file to your application and add it to the AppQualitySwift target.

You can now click the "x" in the upper right corner of the popup to close it -- skipping steps 3 and 4 -- as you will perform those steps here.

Import Firebase module

Start by making sure the Firebase module is imported.

AppDelegate.swift, AQViewController.swift

import Firebase

Configure Firebase in AppDelegate

Use the "configure" method in FirebaseApp inside the application:didFinishLaunchingWithOptions function to configure underlying Firebase services from your .plist file.


  func application(_ application: UIApplication, didFinishLaunchingWithOptions
      launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
  return true

Firebase Performance Monitoring helps you collect performance data from your app, and then review and analyze that data in the Firebase console.

Confirm Firebase Performance Monitoring dependency

Confirm that pod 'Firebase/Performance' dependency exists in your Podfile file.

Automatic traces and network requests

Recompile your app. Automatic traces and HTTP/S network requests are now monitored.

Define a custom trace in your app

A custom trace is a report of performance data associated with some of the code in your app. To learn more about custom traces, see the Performance Monitoring overview. You can have multiple custom traces in your app, and it is possible to have more than one custom trace running at a time.

Start the trace before reading the file.


   let fileName = "\(documentsDirectory)/perfsamplelog.txt"

    // Start tracing
    let trace = Performance.startTrace(name: "request_trace")

    let contents: String

Stop the trace at the completion of the request.


     DispatchQueue.main.async {
        self.imageView.image = UIImage(data: data!)


      let contentToWrite = contents + (response?.url?.absoluteString ?? "")

Add counters to your custom trace

Each custom trace can have one or more counters to count performance-related events in your app, and those counters are associated with the traces that create them.

Set a counter with the log file's size.


   let fileLength = contents.lengthOfBytes(using: .utf8)

    trace?.setValue(Int64(fileLength), forMetric: "log_file_size")

    let target = "https://www.gstatic.com/mobilesdk/160503_mobilesdk/logo/2x/firebase_96dp.png"

Use another counter for the number of requests.


 override func viewDidLoad() {
    let task = URLSession.shared.dataTask(with: request) {
      data, response, error in
    trace?.incrementMetric("request_sent", by: 1)


Add custom attributes to your trace

We can add custom attributes to your traces to filter the trace metrics based on these attributes on the console.

   let fileLength = contents.lengthOfBytes(using: .utf8)

    // Add custom attribute
    let fileLengthString = fileLength > (1024 * 1024) ? ">1MB": "<1MB"
    trace?.setValue(fileLengthString, forAttribute: "file_size")

    let target = "https://www.gstatic.com/mobilesdk/160503_mobilesdk/logo/2x/firebase_96dp.png"

Test Firebase Performance

  1. Click Build and then run the current scheme in Xcode to build your app on a device or simulator.
  2. Confirm that Performance Monitoring results appear in the Firebase console. Results should appear within 24 hours.

Firebase Crashlytics allows your application to report when crashes occur and log the events leading up to the crash.

Confirm Firebase Crashlytics dependency

Confirm that pod 'Firebase/Crashlytics' dependency exists in your Podfile file.

Add the run script build phase

  1. Open your project in Xcode and select its project file in the Navigator.
  2. Open the Build Phases tab.
  3. Click + Add a new build phase, and select New Run Script Phase.
  4. Add the following line to the Type a script... text box:

Add the code to initiate a crash


  @IBAction func didPressCrash(_ sender: AnyObject) {
    print("Crash button pressed!")

Adjust your project's debug settings

Crashlytics uses dSYM (debugging symbol) files to generate human-readable crash reports. Adjust your build settings to change the project's debug information format:

  1. With your project still selected in the Xcode Navigator, open the Build Settings tab.
  2. Click All at the top of the tab to display all build settings.
  3. Search for "debug information format".
  4. Set the Debug Information Format setting to DWARF with dSYM File.

Set up Crashlytics in the Firebase Console

You need to perform a one-time setup in the console before your results will appear.

In the Firebase console:

  1. Click Crashlytics (you may need to expand the Stability tab)
  2. Click Set up Crashlytics
  3. You will see a button to open the documentation. Click it; the documentation opens in a new tab.
  4. Come back to the Firebase console tab and you will see that Crashlytics is now waiting for your first crash report.

Test Firebase Crashlytics

Crashlytics can't capture crashes if your build attaches a debugger at launch

  1. Click Build and then run the current scheme in Xcode to build your app on a device or simulator.
  2. Click Stop running the scheme or action in Xcode to close the initial instance of your app. This initial instance includes a debugger that interferes with Crashlytics.
  3. Open your app again from the simulator or device.
  4. Touch Crash the App to crash the app.
  5. Open your app once more to let the Crashlytics API report the crash. Your crash should show up in the Firebase console within 5 minutes.

You have used Firebase to monitor the quality of an app.

What we've covered

Learn More