[TIL] Firebase

Eden·2025년 7월 15일

Firebase는 Google에서 제공하는 모바일 및 웹 애플리케이션 개발 플랫폼으로, 서버 구축 없이도 다양한 기능을 제공하여 개발 효율성을 높입니다.


1. Firebase란?

  • Google이 제공하는 Backend-as-a-Service(BaaS) 플랫폼
  • iOS, Android, Web 등 다양한 플랫폼 지원
  • 서버 없이도 데이터베이스, 인증, 분석, 푸시 알림 등 기능 구현 가능

2. 주요 기능

기능설명
Authentication이메일, 소셜 로그인(Google, Facebook 등), 익명 로그인
Firestore실시간 NoSQL 클라우드 데이터베이스
Realtime Database실시간 데이터 동기화
Storage이미지, 동영상 등의 파일 저장
Cloud Functions서버리스 함수 실행
Crashlytics앱 크래시 리포트 및 분석
Push NotificationsFirebase Cloud Messaging을 통한 푸시 알림

3. iOS 프로젝트에 Firebase 추가하기

  1. Firebase Console에서 프로젝트 생성

  2. iOS 앱 등록 후 GoogleService-Info.plist 다운로드

  3. Xcode 프로젝트에 GoogleService-Info.plist 추가

  4. Swift Package Manager로 Firebase SDK 설치

    .package(url: "https://github.com/firebase/firebase-ios-sdk.git", from: "10.0.0")
  5. AppDelegate 또는 SceneDelegate에서 초기화

    import FirebaseCore
    
    @main
    class AppDelegate: UIResponder, UIApplicationDelegate {
        func application(_ application: UIApplication,
                         didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
            FirebaseApp.configure()
            return true
        }
    }

4. Firestore 사용 예시

데이터 쓰기

import FirebaseFirestore

let db = Firestore.firestore()
db.collection("users").document("user_1").setData([
    "name": "Alice",
    "age": 25
]) { error in
    if let error = error {
        print("Error writing document: \(error)")
    } else {
        print("Document successfully written!")
    }
}

데이터 읽기

db.collection("users").document("user_1").getDocument { (document, error) in
    if let document = document, document.exists {
        print("Document data: \(document.data() ?? [:])")
    } else {
        print("Document does not exist")
    }
}

5. Firebase Authentication 예시 (이메일 로그인)

import FirebaseAuth

Auth.auth().createUser(withEmail: "test@example.com", password: "password123") { authResult, error in
    if let error = error {
        print("Error: \(error)")
    } else {
        print("User signed up: \(authResult?.user.uid ?? "")")
    }
}

6. Firebase의 장점

  • 빠른 개발 가능 (서버 구축 불필요)
  • 실시간 데이터 동기화
  • 다양한 SDK와 서비스 제공
  • 무료 요금제 제공 (제한적)

7. Firebase의 단점

  • 서버를 직접 제어할 수 없음
  • 요금이 사용량 기반으로 증가 가능
  • 플랫폼 종속성 (Google 서비스)

결론

Firebase는 iOS 앱 개발에서 인증, 데이터베이스, 푸시 알림 등 백엔드 기능을 손쉽게 구현할 수 있는 강력한 도구입니다.
프로토타입부터 상용 서비스까지 유연하게 활용할 수 있습니다.

profile
iOS Dev

0개의 댓글