Bird
Raised Fist0
iOS Swiftmobile~20 mins

Firebase setup for iOS in iOS Swift - Mini App: Build & Ship

Choose your learning style10 modes available
Build: Firebase Setup Screen
This screen helps you verify that Firebase is correctly set up in your iOS app by showing a welcome message after initialization.
Target UI
-------------------------
| Firebase Setup Screen  |
|-----------------------|
|                       |
|  Welcome to Firebase!  |
|                       |
|  [Check Connection]    |
|                       |
-------------------------
Add Firebase SDK initialization in the AppDelegate.
Create a simple UIViewController with a label that says 'Welcome to Firebase!'
Add a button labeled 'Check Connection' that when tapped, prints 'Firebase is configured' to the console.
Ensure the app imports Firebase and configures it properly.
Starter Code
iOS Swift
import UIKit
import Firebase

@main
class AppDelegate: UIResponder, UIApplicationDelegate {

  func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    // TODO: Initialize Firebase here
    return true
  }

  // MARK: UISceneSession Lifecycle
  func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
    return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
  }

  func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
  }
}

class ViewController: UIViewController {

  override func viewDidLoad() {
    super.viewDidLoad()
    view.backgroundColor = .white
    // TODO: Add label and button here
  }
}
Task 1
Task 2
Task 3
Task 4
Solution
iOS Swift
import UIKit
import Firebase

@main
class AppDelegate: UIResponder, UIApplicationDelegate {

  func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    FirebaseApp.configure()
    return true
  }

  func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
    return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
  }

  func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
  }
}

class ViewController: UIViewController {

  private let welcomeLabel: UILabel = {
    let label = UILabel()
    label.text = "Welcome to Firebase!"
    label.textAlignment = .center
    label.font = UIFont.systemFont(ofSize: 24, weight: .medium)
    label.translatesAutoresizingMaskIntoConstraints = false
    return label
  }()

  private let checkButton: UIButton = {
    let button = UIButton(type: .system)
    button.setTitle("Check Connection", for: .normal)
    button.titleLabel?.font = UIFont.systemFont(ofSize: 18, weight: .regular)
    button.translatesAutoresizingMaskIntoConstraints = false
    return button
  }()

  override func viewDidLoad() {
    super.viewDidLoad()
    view.backgroundColor = .white

    view.addSubview(welcomeLabel)
    view.addSubview(checkButton)

    NSLayoutConstraint.activate([
      welcomeLabel.centerXAnchor.constraint(equalTo: view.centerXAnchor),
      welcomeLabel.centerYAnchor.constraint(equalTo: view.centerYAnchor, constant: -20),
      checkButton.topAnchor.constraint(equalTo: welcomeLabel.bottomAnchor, constant: 20),
      checkButton.centerXAnchor.constraint(equalTo: view.centerXAnchor)
    ])

    checkButton.addTarget(self, action: #selector(checkConnectionTapped), for: .touchUpInside)
  }

  @objc private func checkConnectionTapped() {
    print("Firebase is configured")
  }
}

We start by importing Firebase and calling FirebaseApp.configure() in the AppDelegate to initialize Firebase when the app launches.

In the ViewController, we add a label centered on the screen that welcomes the user to Firebase.

Below the label, we add a button labeled 'Check Connection'. When tapped, it prints a confirmation message to the console, showing Firebase is set up correctly.

We use Auto Layout constraints to center the label and position the button below it. This simple UI confirms Firebase initialization visually and via console output.

Final Result
Completed Screen
-------------------------
| Firebase Setup Screen  |
|-----------------------|
|                       |
|  Welcome to Firebase!  |
|                       |
|  [Check Connection]    |
|                       |
-------------------------
Tapping 'Check Connection' prints 'Firebase is configured' in the Xcode console.
Stretch Goal
Add a label below the button that updates to 'Connection OK' when the button is tapped.
💡 Hint
Create a UILabel below the button and update its text inside the button's action method.

Practice

(1/5)
1. What is the first step to set up Firebase for an iOS app?
easy
A. Add Firebase SDK to your Xcode project.
B. Write Swift code to initialize Firebase in your app.
C. Download the GoogleService-Info.plist file.
D. Create a Firebase project and register your iOS app in the Firebase console.

Solution

  1. Step 1: Understand Firebase setup order

    You must first create a Firebase project and register your iOS app in the Firebase console before any code or files.
  2. Step 2: Recognize subsequent steps

    Downloading the plist and adding SDK come after project creation and app registration.
  3. Final Answer:

    Create a Firebase project and register your iOS app in the Firebase console. -> Option D
  4. Quick Check:

    First step = Create project and register app [OK]
Hint: Start by creating the Firebase project online first [OK]
Common Mistakes:
  • Trying to download plist before creating project
  • Initializing Firebase before adding plist
  • Skipping app registration in Firebase console
2. Which Swift code correctly initializes Firebase in your iOS app?
easy
A. Firebase.configureApp()
B. FirebaseApp.configure()
C. Firebase.initialize()
D. FirebaseApp.start()

Solution

  1. Step 1: Recall Firebase initialization method

    The official method to initialize Firebase in Swift is FirebaseApp.configure().
  2. Step 2: Identify incorrect method names

    Other options use wrong method names not defined in Firebase SDK.
  3. Final Answer:

    FirebaseApp.configure() -> Option B
  4. Quick Check:

    Correct method = FirebaseApp.configure() [OK]
Hint: Use FirebaseApp.configure() exactly as shown [OK]
Common Mistakes:
  • Using incorrect method names
  • Calling configure on Firebase instead of FirebaseApp
  • Missing parentheses after configure
3. Given this code snippet in AppDelegate.swift:
import UIKit
import Firebase

@main
class AppDelegate: UIResponder, UIApplicationDelegate {
  func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    FirebaseApp.configure()
    return true
  }
}
What happens when you run the app without adding the GoogleService-Info.plist file?
medium
A. The app crashes at launch due to missing configuration file.
B. Firebase initializes with default settings without errors.
C. The app runs but Firebase features do not work properly.
D. The app shows a compile-time error.

Solution

  1. Step 1: Understand FirebaseApp.configure() behavior

    This method reads GoogleService-Info.plist to configure Firebase. Without it, no crash occurs but Firebase cannot connect properly.
  2. Step 2: Identify runtime effects

    The app runs but Firebase features fail silently or behave incorrectly without the plist file.
  3. Final Answer:

    The app runs but Firebase features do not work properly. -> Option C
  4. Quick Check:

    Missing plist = app runs but Firebase broken [OK]
Hint: Missing plist causes silent Firebase failure, not crash [OK]
Common Mistakes:
  • Assuming app crashes without plist
  • Thinking Firebase uses default config automatically
  • Expecting compile-time errors for missing plist
4. You added Firebase to your iOS app but get a runtime error: "Could not find a valid GoogleService-Info.plist file." What is the most likely cause?
medium
A. You forgot to add the GoogleService-Info.plist file to your Xcode project.
B. You called FirebaseApp.configure() twice in your code.
C. You did not import UIKit in AppDelegate.swift.
D. You did not enable Firebase in the Firebase console.

Solution

  1. Step 1: Analyze the error message

    The error says the plist file is missing or not found, indicating it was not added to the Xcode project properly.
  2. Step 2: Rule out other causes

    Calling configure twice or missing UIKit import won't cause this error. Firebase console enabling is unrelated to local plist file presence.
  3. Final Answer:

    You forgot to add the GoogleService-Info.plist file to your Xcode project. -> Option A
  4. Quick Check:

    Missing plist file in project = runtime error [OK]
Hint: Add plist file to Xcode project to fix missing file error [OK]
Common Mistakes:
  • Ignoring plist file location in Xcode
  • Assuming Firebase console settings cause plist errors
  • Thinking code errors cause missing plist error
5. You want to add Firebase Analytics to your iOS app. After creating the Firebase project and adding your app, which steps must you do to complete setup? Select the correct sequence.
hard
A. Download GoogleService-Info.plist -> Add plist to Xcode -> Add Firebase SDK via Swift Package Manager -> Call FirebaseApp.configure() in AppDelegate
B. Call FirebaseApp.configure() -> Download GoogleService-Info.plist -> Add plist to Xcode -> Add Firebase SDK via CocoaPods
C. Add Firebase SDK via CocoaPods -> Call FirebaseApp.configure() -> Download GoogleService-Info.plist -> Add plist to Xcode
D. Add plist to Xcode -> Download GoogleService-Info.plist -> Add Firebase SDK via Swift Package Manager -> Call FirebaseApp.configure()

Solution

  1. Step 1: Identify correct setup order

    After creating the Firebase project and registering your app, you download the plist file, add it to Xcode, add Firebase SDK (preferably via Swift Package Manager), then initialize Firebase in code.
  2. Step 2: Eliminate incorrect sequences

    Calling configure before adding plist or SDK is wrong. Downloading plist after calling configure causes errors. Adding plist before downloading is impossible.
  3. Final Answer:

    Download GoogleService-Info.plist -> Add plist to Xcode -> Add Firebase SDK via Swift Package Manager -> Call FirebaseApp.configure() in AppDelegate -> Option A
  4. Quick Check:

    Correct setup order = plist download, add, SDK add, configure [OK]
Hint: Follow setup steps in order: plist, add, SDK, configure [OK]
Common Mistakes:
  • Calling configure before adding plist
  • Adding plist after calling configure
  • Mixing SDK installation methods incorrectly
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard