How to setup Fabric

Add Fabric for easy app release.

This post is a continuation of the app initialization process, it will be better if you read all of the previous posts first. Click here to see the list of previous posts.

If you haven’t used Fabric yet maybe it’s a good time to give it a try. Fabric is a mobile platform that will improve your development environment. It has a lot of components, but most interesting kits are:

  • Beta - App distribution for beta testing (iOS)
  • Crashlytics - Crash reporting (iOS, OS X, tvOS)
  • Answers - Real-time analytics and event tracking (iOS, OS X, tvOS)

To start using it you have to create an account at Fabric website and install Fabric macOS app, which you can download from here.

Fabric login

After you sign in, click + New App > Browse... and search for iOSProjectStarter.xcworkspace and click Open:

Fabric login

Now you have to select what kit you would like to install. Click install on Crashlytics:

Fabric login

You can install Fabric using CocoaPods or copy files manually:

Select method

Let’s add it using Podfile:

Edit podfile

We already have those pods installed, so skip this step, just click Next.

Integrate with Xcode

On this screen just click Copy button, it should copy command visible on screen to your clipboard.

Add new run script phase

Now let’s get back to Xcode, select target iOSProjectStarter > Build Phases click + button and select New Run Script Phase. It will create new Run Script, just put there this command that you have in clipboard. This script will run with every build. To finish this step just start the build process (⌘B).

Start Fabric in AppDelegate

This is the last step. Inside AppDelegate.swift file import Fabric and Crashlytics. Simply just click on the blue highlight to copy it to clipboard and then paste this code to AppDelegate file:

import UIKit
import Fabric
import Crashlytics

class AppDelegate: UIResponder, UIApplicationDelegate {

  var window: UIWindow?

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

    self.window = UIWindow(frame: UIScreen.main.bounds)

    let mainVC = ViewController()
    self.window?.rootViewController = mainVC
    self.window?.makeKeyAndVisible()

    Fabric.with([Crashlytics.self])

    return true
  }
  [...]

After that just run your app (⌘R) in Fabric you should see installation complete screen:

Installation complete

That’s all for now, our setup is complete. We can now use it to bootstrap a new project: SwiftNews.