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 Dec 15, 2021
commit 4ff41d7b4e543f6ef740725e1d6b9f92a18fb9ff
Original file line number Diff line number Diff line change
Expand Up @@ -56,30 +56,30 @@ extension DocumentReference {
}
}

// TODO: How do you annotate that using Xcode 13.2 you can actually compile to earlier os versions
#if compiler(>=5.5) && canImport(_Concurrency)
/// 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
/// caller-specified type.
/// ```swift
/// let book = try await ref.getDocument(as: Book.self)
/// ```
/// - Parameters:
/// - as: A `Decodable` type to convert the document fields to.
/// - serverTimestampBehavior: Configures how server timestamps that have
/// not yet been set to their final value are returned from the snapshot.
/// - decoder: The decoder to use to convert the document. `nil` to use
/// - 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 {
// TODO: How do you annotate that using Xcode 13.2 you can actually compile to earlier os versions
mortenbekditlevsen marked this conversation as resolved.
Show resolved Hide resolved
#if compiler(>=5.5) && canImport(_Concurrency)
/// 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
/// caller-specified type.
/// ```swift
/// let book = try await ref.getDocument(as: Book.self)
mortenbekditlevsen marked this conversation as resolved.
Show resolved Hide resolved
/// ```
/// - Parameters:
/// - as: A `Decodable` type to convert the document fields to.
/// - serverTimestampBehavior: Configures how server timestamps that have
/// not yet been set to their final value are returned from the snapshot.
/// - decoder: The decoder to use to convert the document. `nil` to use
mortenbekditlevsen marked this conversation as resolved.
Show resolved Hide resolved
/// - 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 {
let snapshot = try await getDocument()
return try snapshot.data(as: T.self,
with: serverTimestampBehavior,
decoder: decoder)
}
#endif
with: serverTimestampBehavior,
decoder: decoder)
}
#endif
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import FirebaseFirestore

extension DocumentSnapshot {
/// Retrieves all fields in a document and converts them to an instance of
/// caller-specified type.
/// caller-specified type.
///
/// By default, server-provided timestamps that have not yet been set to their
/// final value will be returned as `NSNull`. Pass `serverTimestampBehavior`
mortenbekditlevsen marked this conversation as resolved.
Show resolved Hide resolved
Expand Down