A Swift package providing an abstracted service layer for Firebase Cloud Firestore. This package simplifies Firestore CRUD operations by defining structured endpoints and leveraging Swift's async/await and Codable features. Compatible with both SwiftUI and UIKit applications.
- iOS 15.0+
- Swift 5.9+
- In Xcode, open your project and navigate to
File
→Swift Packages
→Add Package Dependency...
- Paste the repository URL:
https://github.com/yasuntimure/FirestoreService.git
- Click on
Next
and select the latest version. - Click on
Next
and let Xcode resolve the package.
After importing the package into your project:
import FirestoreService
public enum TestEndpoint: FirestoreEndpoint {
case getItems
case postItem(dto: TestItem)
public var path: FirestoreReference {
switch self {
case .getItems:
return firestore.collection("items")
case .postItem(let dto):
return firestore.collection("items").document(dto.id)
}
}
public var method: FirestoreMethod {
switch self {
case .getItems:
return .get
case .postItem(let dto):
return .post(dto)
}
}
}
Task {
do {
let endpoint = TestEndpoint.getItems
self.items = try await FirestoreService.request(endpoint)
} catch {
print("Error: ", error.localizedDescription)
}
}