毎回どうするんだっけなと過去のプロジェクト開くのがめんどいから
MyFirebase.swift
import Firebase
//コード内にマクロ入れるとごちゃつくのでここで定数化しておく
#if DEBUG
let IS_DEBUG = true
#else
let IS_DEBUG = false
#endif
import UIKit
import Firebase
class MyAppFirebase:NSObject{
static let shared = MyAppFirebase()
static var FIREBASE_PLIST_NAME:String{
return IS_DEBUG ? "d_GoogleService-Info" : "GoogleService-Info"
}
private override init() {
super.init()
guard let path = Bundle.main.path(forResource: MyAppFirebase.FIREBASE_PLIST_NAME, ofType: "plist") else {
print("invalid firebase plist file : \(MyAppFirebase.FIREBASE_PLIST_NAME)")
return
}
guard let firbaseOptions = FirebaseOptions(contentsOfFile: path) else {
print("not make firbaseOptions : \(MyAppFirebase.FIREBASE_PLIST_NAME)")
return
}
FirebaseApp.configure(options: firbaseOptions)
}
}
使う時はこんな感じ
AppDelegate.swift
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
//初期化だけするよ
_ = MyFirebase.shared
}