Add skip geo and reference flag

This commit is contained in:
Oleksii Dykan
2018-01-25 16:33:32 +01:00
parent 31ecb57f14
commit 9fa47dd610
3 changed files with 8 additions and 1 deletions

View File

@@ -13,6 +13,7 @@ class _FirebaseDecoder : Decoder {
struct _Options {
let dateDecodingStrategy: FirebaseDecoder.DateDecodingStrategy?
let dataDecodingStrategy: FirebaseDecoder.DataDecodingStrategy?
let skipGeoPointAndReference: Bool
let userInfo: [CodingUserInfoKey : Any]
}

View File

@@ -53,6 +53,7 @@ open class FirebaseDecoder {
let options = _FirebaseDecoder._Options(
dateDecodingStrategy: dateDecodingStrategy,
dataDecodingStrategy: dataDecodingStrategy,
skipGeoPointAndReference: false,
userInfo: userInfo
)
let decoder = _FirebaseDecoder(referencing: container, options: options)

View File

@@ -14,7 +14,12 @@ open class FirestoreDecoder {
open var userInfo: [CodingUserInfoKey : Any] = [:]
open func decode<T : Decodable>(_ type: T.Type, from container: [String: Any]) throws -> T {
let options = _FirebaseDecoder._Options(dateDecodingStrategy: nil, dataDecodingStrategy: nil, userInfo: userInfo)
let options = _FirebaseDecoder._Options(
dateDecodingStrategy: nil,
dataDecodingStrategy: nil,
skipGeoPointAndReference: true,
userInfo: userInfo
)
let decoder = _FirebaseDecoder(referencing: container, options: options)
guard let value = try decoder.unbox(container, as: T.self) else {
throw DecodingError.valueNotFound(T.self, DecodingError.Context(codingPath: [], debugDescription: "The given dictionary was invalid"))