Introduction
Firebase gives you ready-made tools to handle your app's data and users. This saves you time and effort so you can focus on making your app great.
Firebase gives you ready-made tools to handle your app's data and users. This saves you time and effort so you can focus on making your app great.
import Firebase // Initialize Firebase in your app delegate FirebaseApp.configure()
import Firebase
FirebaseApp.configure()import FirebaseFirestore let db = Firestore.firestore() db.collection("users").addDocument(data: ["name": "Anna"])
This app initializes Firebase and shows a button. When you tap the button, it saves a message to Firebase Firestore. The app shows if the save was successful or if there was an error.
import SwiftUI import Firebase import FirebaseFirestore @main struct MyApp: App { init() { FirebaseApp.configure() } var body: some Scene { WindowGroup { ContentView() } } } struct ContentView: View { @State private var message = "" var body: some View { VStack { Text("Firebase is ready!") .font(.title) .padding() Text(message) .padding() Button("Save Message") { let db = Firestore.firestore() db.collection("messages").addDocument(data: ["text": "Hello from SwiftUI!"]) { error in if let error = error { message = "Error: \(error.localizedDescription)" } else { message = "Message saved successfully!" } } } .padding() } } }
Firebase provides ready backend services to save you time.
You can store data, authenticate users, and get real-time updates easily.
Initialize Firebase once and then use its tools throughout your app.
let ref = Database.database().reference()
ref.child("messages").setValue(["Hello", "World"])
ref.child("messages").observe(.value) { snapshot in
if let messages = snapshot.value as? [String] {
print(messages.joined(separator: ", "))
}
}
What will be printed in the console?Auth.auth().signIn(withEmail: email, password: password) { authResult, error in
if error != nil {
print("Login failed")
} else {
print("Login successful")
}
}
But the app always prints "Login failed" even with correct credentials. What is the likely issue?Pass the test and this pattern moves unknown