Starting with iOS
To run on a physical device:
Connect the device
Turn on Developer Mode on iPhone (Settings > Privacy & Security > Developer Mode)
Trust the Developer App on iPhone ( Settings > General > VPN & Device Management)
Establish a Team in XCode (Project > Signing & Capabilities > Team)
Getting Firestore up and running
Need to drag the GoogleService-Info.plist to your project directory
Need to Add SDK
In Xcode, with your app project open, navigate to File > Add Packages
When prompted, enter the Firebase iOS SDK repository URL `https://github.com/firebase/firebase-ios-sdk`
Choose at least the Firestore packages (but not all of the packages and not the combined packages)
Add the following code to the App file
import SwiftUI
import FirebaseCore
import FirebaseFirestore
//import FirebaseFirestoreSwift
class AppDelegate: NSObject, UIApplicationDelegate {
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
FirebaseApp.configure()
addDoc()
return true
}
}
func addDoc(){
let db = Firestore.firestore()
//db.collection("Documents").addDocument(data: ["name": "ming"])
let docRef = db.collection("Restaurants").document("hello")
docRef.setData(["name": "Favorite Restaurant!!"]) { error in
if let error = error {
print("Error writing document: \(error)")
} else {
print("Document successfully written!")
}
}
}
@main
struct FirestoreApp: App {
@UIApplicationDelegateAdaptor(AppDelegate.self) var delegate
var body: some Scene {
WindowGroup {
ContentView()
}
}
}