Skip to content

Instantly share code, notes, and snippets.

@yimajo
Last active April 20, 2023 04:08
Show Gist options
  • Save yimajo/ec4edd7ec7af8a3697b8a3323a818bcf to your computer and use it in GitHub Desktop.
Save yimajo/ec4edd7ec7af8a3697b8a3323a818bcf to your computer and use it in GitHub Desktop.
import FirebaseFirestore
import FirebaseFirestoreSwift
import Foundation
// MARK: - CollectionReference
public extension CollectionReference {
@discardableResult
func add<T: Encodable>(
_ value: T,
encoder: Firestore.Encoder = Firestore.Encoder()
) async throws -> DocumentReference {
try await addDocument(data: try encoder.encode(value))
}
}
// MARK: - DocumentReference
public extension DocumentReference {
func update<T: Encodable>(
_ value: T,
encoder: Firestore.Encoder = Firestore.Encoder()
) async throws {
try await updateData(try encoder.encode(value))
}
func set<T: Encodable>(
_ value: T,
encoder: Firestore.Encoder = Firestore.Encoder()
) async throws {
try await setData(try encoder.encode(value))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment