magicbell-io / magicbell-swift Goto Github PK
View Code? Open in Web Editor NEWOfficial MagicBell iOS SDK
Home Page: https://magicbell.com
License: Other
Official MagicBell iOS SDK
Home Page: https://magicbell.com
License: Other
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.