Learning SwiftUI, MVVM and Firebase

Mike Haslam
5 min readMay 9, 2021

Getting past just following a tutorial

SwiftUI, MVVM and Firebase

SwiftUI is such a pleasure for a new iOS developer like myself. When you combine it with Firebase, it’s so much easier now to build robust apps. I want to share my journey in building a simple social media app.

I created a repository on GitHub that hopefully will be useful for others. I am always open for feedback, and other contributors would be super cool.

GitHub repository

In the app I’m working on, a user needs to create a story with an image. Also, it needs to be editable and the user should be able to delete their story. For the structure of the app, I choose to use the MVVM pattern.

So I went searching for some tutorials to get me started. I found a very helpful tutorial from the gang at Ray Wenderlich.


The problem was once again tutorials only take you so far. The first challenge I encountered in following the RW tutorial was getting the Firebase SDK set up and initialized.

The reason being is my app uses the SwiftUI App Lifecycle so there is no scene or app delegate files. After a quick search, I found this solution. https://medium.com/firebase-developers/firebase-and-the-new-swiftui-2-application-life-cycle-e568c9f744e9

I used the @UIApplicationDelegateAdaptor property wrapper to connect the app to an instance of AppDelegate.

import SwiftUI
import Firebase
@mainstruct Firebase_SwiftUI_MVVMApp: App {@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate

var body: some Scene {
WindowGroup {
class AppDelegate: NSObject, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions:[UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
return true

The next challenge I was faced with was how to add an UIImage to my Story model. I learned in the RW tutorial that FirebaseFirestoreSwift…