Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Require explicit typing for DocumentSnapshot decoding. DocumentReference decoding. #9101

Merged
Prev Previous commit
Next Next commit
Ran style.sh
  • Loading branch information
mortenbekditlevsen committed Jan 23, 2022
commit 2eb244f9d372357b8d0d14cbf9512dd1fb5d2308
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import Foundation
import FirebaseFirestore

extension DocumentReference {
public extension DocumentReference {
/// Fetches and decodes the document referenced by this `DocumentReference`.
///
/// This allows users to retrieve a Firestore document and have it decoded to an instance of
Expand All @@ -38,11 +38,11 @@ extension DocumentReference {
/// - decoder: The decoder to use to convert the document. `nil` to use
mortenbekditlevsen marked this conversation as resolved.
Show resolved Hide resolved
/// default decoder.
/// - completion: The closure to call when the document snapshot has been fetched and decoded.
public func getDocument<T: Decodable>(as type: T.Type,
with serverTimestampBehavior: ServerTimestampBehavior =
.none,
decoder: Firestore.Decoder? = nil,
completion: @escaping (Result<T, Error>) -> Void) {
func getDocument<T: Decodable>(as type: T.Type,
schmidt-sebastian marked this conversation as resolved.
Show resolved Hide resolved
with serverTimestampBehavior: ServerTimestampBehavior =
.none,
decoder: Firestore.Decoder? = nil,
completion: @escaping (Result<T, Error>) -> Void) {
getDocument { snapshot, error in
guard let snapshot = snapshot else {
completion(.failure(error ?? FirestoreDecodingError.internal))
mortenbekditlevsen marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -77,10 +77,10 @@ extension DocumentReference {
/// default decoder.
/// - Returns: This instance of the supplied `Decodable` type `T`.
@available(iOS 15, tvOS 15, macOS 12, watchOS 8, *)
public func getDocument<T: Decodable>(as type: T.Type,
with serverTimestampBehavior: ServerTimestampBehavior =
.none,
decoder: Firestore.Decoder? = nil) async throws -> T {
func getDocument<T: Decodable>(as type: T.Type,
with serverTimestampBehavior: ServerTimestampBehavior =
.none,
decoder: Firestore.Decoder? = nil) async throws -> T {
let snapshot = try await getDocument()
return try snapshot.data(as: T.self,
with: serverTimestampBehavior,
Expand Down