88
99import Foundation
1010
11+ public protocol GeoPointType : Codable {
12+ var latitude : Double { get }
13+ var longitude : Double { get }
14+ init ( latitude: Double , longitude: Double )
15+ }
16+
17+ public protocol DocumentReferenceType : Codable { }
18+
1119open class FirestoreDecoder {
1220 public init ( ) { }
1321
1422 open var userInfo : [ CodingUserInfoKey : Any ] = [ : ]
1523
1624 open func decode< T : Decodable > ( _ type: T . Type , from container: [ String : Any ] ) throws -> T {
17- let options = _FirebaseDecoder. _Options ( dateDecodingStrategy: nil , dataDecodingStrategy: nil , userInfo: userInfo)
25+ let options = _FirebaseDecoder. _Options (
26+ dateDecodingStrategy: nil ,
27+ dataDecodingStrategy: nil ,
28+ skipGeoPointAndReference: true ,
29+ userInfo: userInfo
30+ )
1831 let decoder = _FirebaseDecoder ( referencing: container, options: options)
1932 guard let value = try decoder. unbox ( container, as: T . self) else {
2033 throw DecodingError . valueNotFound ( T . self, DecodingError . Context ( codingPath: [ ] , debugDescription: " The given dictionary was invalid " ) )
@@ -23,3 +36,37 @@ open class FirestoreDecoder {
2336 return value
2437 }
2538}
39+
40+ enum GeoPointKeys : CodingKey {
41+ case latitude, longitude
42+ }
43+
44+ extension GeoPointType {
45+ public init ( from decoder: Decoder ) throws {
46+ let container = try decoder. container ( keyedBy: GeoPointKeys . self)
47+ let latitude = try container. decode ( Double . self, forKey: . latitude)
48+ let longitude = try container. decode ( Double . self, forKey: . longitude)
49+ self . init ( latitude: latitude, longitude: longitude)
50+ }
51+
52+ public func encode( to encoder: Encoder ) throws {
53+ var container = encoder. container ( keyedBy: GeoPointKeys . self)
54+ try container. encode ( latitude, forKey: . latitude)
55+ try container. encode ( longitude, forKey: . longitude)
56+ }
57+ }
58+
59+ enum DocumentReferenceError : Error {
60+ case typeIsNotSupported
61+ case typeIsNotNSObject
62+ }
63+
64+ extension DocumentReferenceType {
65+ public init ( from decoder: Decoder ) throws {
66+ throw DocumentReferenceError . typeIsNotSupported
67+ }
68+
69+ public func encode( to encoder: Encoder ) throws {
70+ throw DocumentReferenceError . typeIsNotSupported
71+ }
72+ }
0 commit comments