Last active
April 20, 2023 04:08
-
-
Save yimajo/ec4edd7ec7af8a3697b8a3323a818bcf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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