@@ -18,8 +18,6 @@ import Foundation
18
18
19
19
extension Firestore {
20
20
public struct Decoder {
21
- fileprivate static let documentRefUserInfoKey = CodingUserInfoKey ( rawValue: " DocumentRefUserInfoKey " )
22
-
23
21
public init ( ) { }
24
22
/// Returns an instance of specified type from a Firestore document.
25
23
///
@@ -28,22 +26,13 @@ extension Firestore {
28
26
/// in `container` are directly supported:
29
27
/// - GeoPoint
30
28
/// - Timestamp
31
- /// - DocumentReference
32
29
///
33
30
/// - Parameters:
34
31
/// - A type to decode a document to.
35
32
/// - container: A Map keyed of String representing a Firestore document.
36
- /// - document: A reference to the Firestore Document that is being
37
- /// decoded.
38
33
/// - Returns: An instance of specified type by the first parameter.
39
- public func decode< T: Decodable > ( _: T . Type ,
40
- from container: [ String : Any ] ,
41
- in document: DocumentReference ? = nil ) throws -> T {
34
+ public func decode< T: Decodable > ( _: T . Type , from container: [ String : Any ] ) throws -> T {
42
35
let decoder = _FirestoreDecoder ( referencing: container)
43
- if let doc = document {
44
- decoder. userInfo [ Firestore . Decoder. documentRefUserInfoKey!] = doc
45
- }
46
-
47
36
guard let value = try decoder. unbox ( container, as: T . self) else {
48
37
throw DecodingError . valueNotFound (
49
38
T . self,
@@ -333,24 +322,6 @@ private struct _FirestoreKeyedDecodingContainer<K: CodingKey>: KeyedDecodingCont
333
322
}
334
323
335
324
public func decode< T: Decodable > ( _: T . Type , forKey key: Key ) throws -> T {
336
- if T . self == SelfDocumentID . self {
337
- let docRef = decoder. userInfo [
338
- Firestore . Decoder. documentRefUserInfoKey!
339
- ] as! DocumentReference ?
340
-
341
- if contains ( key) {
342
- let docPath = ( docRef != nil ) ? docRef!. path : " nil "
343
- var codingPathCopy = codingPath. map { key in key. stringValue }
344
- codingPathCopy. append ( key. stringValue)
345
-
346
- throw FirestoreDecodingError . fieldNameConfict ( " Field name " +
347
- " \( codingPathCopy) was found from document \" \( docPath) \" , " +
348
- " cannot assign the document reference to this field. " )
349
- }
350
-
351
- return SelfDocumentID ( from: docRef) as! T
352
- }
353
-
354
325
let entry = try require ( key: key)
355
326
356
327
decoder. codingPath. append ( key)
@@ -1006,10 +977,6 @@ extension _FirestoreDecoder {
1006
977
1007
978
func unbox( _ value: Any , as type: Date . Type ) throws -> Date ? {
1008
979
guard !( value is NSNull ) else { return nil }
1009
- // Firestore returns all dates as Timestamp, converting it to Date so it can be used in custom objects.
1010
- if let timestamp = value as? Timestamp {
1011
- return timestamp. dateValue ( )
1012
- }
1013
980
guard let date = value as? Date else {
1014
981
throw DecodingError . _typeMismatch ( at: codingPath, expectation: type, reality: value)
1015
982
}
@@ -1066,7 +1033,7 @@ extension _FirestoreDecoder {
1066
1033
}
1067
1034
}
1068
1035
1069
- // Decoding an embedded container, this requires expanding the storage stack and
1036
+ // Decoding an embeded container, this requires expanding the storage stack and
1070
1037
// then restore after decoding.
1071
1038
storage. push ( container: value)
1072
1039
let decoded = try T ( from: self )
0 commit comments