Do You Need a Backend?
Many apps work fully on the device. You need a backend when users need accounts, shared data between people, or sync across devices.
| Option | Good for | Notes |
| SwiftData + CloudKit | Sync between a user's own devices | No server code, Apple only |
| CloudKit public/shared DB | Simple sharing between users | Apple platforms only |
| Firebase | Accounts, database, storage, analytics, push | Fast to start, works across Android and web |
| Your own REST API | Full control, company backend | Use URLSession and Codable |
Adding Firebase (Overview)
- Create a project at the Firebase console and add an iOS app with your bundle id.
- Download
GoogleService-Info.plist and drag it into Xcode.
- Add the package
https://github.com/firebase/firebase-ios-sdk using File > Add Package Dependencies.
- Choose the libraries you need, for example FirebaseAuth and FirebaseFirestore.
swift
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 MyApp: App {
@UIApplicationDelegateAdaptor(AppDelegate.self) var delegate
var body: some Scene { WindowGroup { ContentView() } }
}
swift
import FirebaseAuth
import FirebaseFirestore
// Sign up
let result = try await Auth.auth().createUser(withEmail: email, password: password)
print(result.user.uid)
// Save a document
try await Firestore.firestore().collection("notes").document(UUID().uuidString)
.setData(["text": "Hello", "createdAt": Timestamp(date: .now)])
// Read documents
let snapshot = try await Firestore.firestore().collection("notes").getDocuments()
let texts = snapshot.documents.compactMap { $0["text"] as? String }
Security rules: Always set Firestore security rules so users can only read and write their own data. Never leave a database open to everyone.
Sign in with Apple
Apps that offer third-party sign-in options (such as Google or Facebook) are required by the App Store guidelines to also offer Sign in with Apple or an equivalent privacy-focused option. Check the current guideline text before you submit.
swift
import AuthenticationServices
SignInWithAppleButton(.signIn) { request in
request.requestedScopes = [.fullName, .email]
} onCompletion: { result in
switch result {
case .success(let auth):
if let credential = auth.credential as? ASAuthorizationAppleIDCredential {
let userID = credential.user // stable ID for this user
print("Signed in: \(userID)")
}
case .failure(let error):
print(error.localizedDescription)
}
}
.frame(height: 50)
Add the Sign in with Apple capability in Signing & Capabilities first.
Advice: For a learning project start with SwiftData only. Add a backend later when a real need appears.
Conclusion
Choose the simplest backend that solves your problem. SwiftData with CloudKit for private sync, Firebase for cross-platform accounts and data, or your own API for full control.
Quick Summary: Use CloudKit for private sync, Firebase for fast cloud features and Sign in with Apple for privacy-friendly login.