alickbass / CodableFirebase

Use Codable with Firebase
MIT License
691 stars 91 forks source link

Unable to decode GeoPoint #29

Closed hpbl closed 6 years ago

hpbl commented 6 years ago

Hi, the following code is failing:

        let model = try FirebaseDecoder().decode(
            FirestoreSpot.self,
            from: modelDict
        )

modelDict's decode is failing on the key "location". The location property is of type GeoPoint, and as you can see bellow, modelDict has the correct type:

(lldb) po modelDict["location"]! is GeoPoint
true

the error I'm getting is that the value for this key is not a dictionary (which it shouldn't be):

(lldb) po error
▿ DecodingError
  ▿ typeMismatch : 2 elements
    - .0 : Swift.Dictionary<Swift.String, Any>
    ▿ .1 : Context
      ▿ codingPath : 1 element
        - 0 : SurfSpotter.FirestoreSpot.CodingKeys.location
      - debugDescription : "Not a dictionary"
      - underlyingError : nil

Can anyone help me? Am I missing something?

Thanks

alickbass commented 6 years ago

Hi! Thanks for reaching out! Please, try to use FirestoreDecoder instead. GeoPoint is only relevant to Firestore

hpbl commented 6 years ago

Yeah, sorry about that, I just realized this, and was about to post it myself. Thanks for the quick feedback and for the pod. 😊

martindufort commented 6 years ago

Hey @hpbl did you resolve this issue ? Because you code is actually using a FirebaseDecoder. Did you switch to FirestoreDecoder instead ?

hpbl commented 6 years ago

@martindufort Yes, switching to FirestoreDecoder fixes it

hpbl commented 6 years ago

@alickbass edit your comment so it reads "try to use FirestoreDecoder instead..."