alickbass / CodableFirebase

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

Parsing error #68

Closed adnanatflo closed 5 years ago

adnanatflo commented 5 years ago

This my Struct :

struct Goal : Codable { var goalnotes : String? var link : String? var name : String? var tags : String? var target_points : Int? var total_points : Int? var youtube : String? var point_items : [String: Point]? }

struct Point : Codable { var points : Int? var userNotes : String? }

I have successfully decode "Goal" modal but i cant decode "point_items" to array. This is my code for decoding "point_items". please help me to fix this problem.

        guard let value = goal?.point_items  else { return }
        do {

            let point = try FirebaseDecoder().decode([Point].self, from:Array(value.values))
        } catch let error {
            print(error)
        }

Help would be much appreciated.

serjooo commented 5 years ago

I really don't see what you are trying to achieve. If you have a Dictionary<String, Point> and if you call values on it and convert it into Array(values) you already do have what you are trying to decode without actually decoding it.

If you test Array(value.values) is [Point] that should print true and that's even before decoding to the type you want.

Maybe I misunderstood your problem or your point if you can provide a minimum testable problem that we can reproduce in a playground or project we can help more.