Setup Firebase to Use MacOS
SwiftUI ONLY! (Does not include MacOS Syntax)
I was following Firebases Setup up and config from the Firebase Website. I was installing FirebaseAuth, FirebaseStorage, FirebaseFirestore using Xcodes 14 “add packages” service: File ->AddPackages
import SwiftUI
import FirebaseCore
class AppDelegate: NSObject, UIApplicationDelegate {
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
FirebaseApp.configure()
return true
}
}
@main
struct YourApp: App {
// register app delegate for Firebase setup
@UIApplicationDelegateAdaptor(AppDelegate.self) var delegate
var body: some Scene {
WindowGroup {
NavigationView {
ContentView()
}
}
}
}
Firebase MacOS
Found the below code snippet solution at StackOverFlow.com. If you are start your project fresh. You will have two files ContentView.swift and “MyApp.swift” <- or what ever you named your app. In the MyApp.swift file substitute the generic start up script with the below snippet.
import FirebaseCore
import SwiftUI
class AppDelegate: NSObject, NSApplicationDelegate {
func applicationDidFinishLaunching(_ notification: Notification) {
FirebaseApp.configure()
}
}
@main
struct ImageManagerApp: App {
@NSApplicationDelegateAdaptor(AppDelegate.self) var delegate
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
Hope it works well for you and best wishes in your developing journey!