Git Product home page Git Product logo

magicbell-swift's People

Contributors

jfilowk avatar josuemontano avatar stigi avatar vilanovi avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

stigi

magicbell-swift's Issues

Error while decoding preferences fetch response

I have an exception There was an error while mapping UserPreferencesEntity when executing the following call:

if let preferences = self.connectedUser?.preferences {
            preferences.fetch { result in
                switch result {
                case .success(let userPreferences):
                    print(userPreferences.preferences.keys)
                    break
                case .failure(let error):
                    break
                }
            }
        }

Here's the line where the exception happens (in UserPreferencesEntity):

preferences = try values.decode([String: PreferencesEntity].self, forKey: .categories)

After some investigation, it seems that the swift struct is not corresponding to the received JSON.

After decoding the notification_preferences container and categories subcontainer, the code try to decode the map [String: PerferencesEntity].

Here's the PreferencesEntity struct:

struct PreferencesEntity: Codable {

    var email: Bool
    var inApp: Bool
    var mobilePush: Bool
    var webPush: Bool

    enum CodingKeys: String, CodingKey {
        case email
        case inApp = "in_app"
        case mobilePush = "mobile_push"
        case webPush = "web_push"
    }

    init(from decoder: Decoder) throws {
        let values = try decoder.container(keyedBy: CodingKeys.self)
        email = try values.decodeIfPresent(Bool.self, forKey: .email) ?? false
        inApp = try values.decodeIfPresent(Bool.self, forKey: .inApp) ?? false
        mobilePush = try values.decodeIfPresent(Bool.self, forKey: .mobilePush) ?? false
        webPush = try values.decodeIfPresent(Bool.self, forKey: .webPush) ?? false
    }

...
}

But here's the JSON that this code try to decode:

{
   "notification_preferences":{
      "categories":[
         {
            "label":"creator-digital-asset-minting-finished",
            "slug":"creator-digital-asset-minting-finished",
            "channels":[
               {
                  "label":"In app",
                  "slug":"in_app",
                  "enabled":true
               },
               {
                  "label":"Mobile push",
                  "slug":"mobile_push",
                  "enabled":true
               },
               {
                  "label":"Web push",
                  "slug":"web_push",
                  "enabled":true
               },
               {
                  "label":"Email",
                  "slug":"email",
                  "enabled":true
               },
               {
                  "label":"Slack",
                  "slug":"slack",
                  "enabled":true
               },
               {
                  "label":"SMS",
                  "slug":"sms",
                  "enabled":true
               }
            ]
         }, 
         ...
         ]
    }
}

Which doesn't seems to match the current struct.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.