Skip to content

Commit faa4488

Browse files
authored
Address PR feedback for Firestore Codable (#10270)
* Address PR feedback for Firestore Codable * revert error message change
1 parent 79f9cba commit faa4488

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

Firestore/Swift/Source/Codable/DocumentID.swift

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@
1717
import FirebaseFirestore
1818
import FirebaseSharedSwift
1919

20-
let documentRefUserInfoKey =
21-
CodingUserInfoKey(rawValue: "DocumentRefUserInfoKey")!
20+
extension CodingUserInfoKey {
21+
static let documentRefUserInfoKey =
22+
CodingUserInfoKey(rawValue: "DocumentRefUserInfoKey")!
23+
}
2224

2325
/// A type that can initialize itself from a Firestore `DocumentReference`,
2426
/// which makes it suitable for use with the `@DocumentID` property wrapper.
@@ -105,9 +107,10 @@ public struct DocumentID<Value: DocumentIDWrappable & Codable>:
105107
// MARK: - `Codable` implementation.
106108

107109
public init(from decoder: Decoder) throws {
108-
guard let reference = decoder.userInfo[documentRefUserInfoKey] as? DocumentReference else {
110+
guard let reference = decoder
111+
.userInfo[CodingUserInfoKey.documentRefUserInfoKey] as? DocumentReference else {
109112
throw FirestoreDecodingError.decodingIsNotSupported(
110-
"Could not find DocumentReference for user info key: \(documentRefUserInfoKey)"
113+
"Could not find DocumentReference for user info key: \(CodingUserInfoKey.documentRefUserInfoKey)"
111114
)
112115
}
113116
try self.init(from: reference)

Firestore/Swift/Source/Codable/EncoderDecoder.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public extension Firestore {
9090
public func decode<T: Decodable>(_ t: T.Type, from data: Any,
9191
in reference: DocumentReference?) throws -> T {
9292
if let reference = reference {
93-
userInfo[documentRefUserInfoKey] = reference
93+
userInfo[CodingUserInfoKey.documentRefUserInfoKey] = reference
9494
}
9595
return try decode(T.self, from: data)
9696
}

0 commit comments

Comments
 (0)