From e0f791b9a623d133ece58facef512ca01fef13d0 Mon Sep 17 00:00:00 2001 From: Cameron McOnie Date: Wed, 10 Jun 2020 18:21:36 +0200 Subject: [PATCH] Decode properties properties present. --- Sources/Core/Models/User/UserModel.swift | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Sources/Core/Models/User/UserModel.swift b/Sources/Core/Models/User/UserModel.swift index 4e7c8917..a62cf7e7 100644 --- a/Sources/Core/Models/User/UserModel.swift +++ b/Sources/Core/Models/User/UserModel.swift @@ -84,14 +84,14 @@ extension UserModel: Codable { // de-nest properties to top level let propertiesContainer = try items.nestedContainer(keyedBy: PropertiesCodingKeys.self, forKey: .properties) - firstName = try propertiesContainer.decode(String.self, forKey: .firstName) - lastName = try propertiesContainer.decode(String.self, forKey: .lastName) - isNamePublic = try propertiesContainer.decode(Bool.self, forKey: .isNamePublic) - isAvatarPublic = try propertiesContainer.decode(Bool.self, forKey: .isAvatarPublic) - birthday = try propertiesContainer.decode(String.self, forKey: .birthday) - guestID = try propertiesContainer.decode(String.self, forKey: .guestID) - nonPushNotification = try propertiesContainer.decode(Bool.self, forKey: .nonPushNotification) - language = try propertiesContainer.decode(String.self, forKey: .language) + firstName = try propertiesContainer.decodeIfPresent(String.self, forKey: .firstName) ?? "" + lastName = try propertiesContainer.decodeIfPresent(String.self, forKey: .lastName) ?? "" + isNamePublic = try propertiesContainer.decodeIfPresent(Bool.self, forKey: .isNamePublic) ?? false + isAvatarPublic = try propertiesContainer.decodeIfPresent(Bool.self, forKey: .isAvatarPublic) ?? false + birthday = try propertiesContainer.decodeIfPresent(String.self, forKey: .birthday) ?? "" + guestID = try propertiesContainer.decodeIfPresent(String.self, forKey: .guestID) ?? "" + nonPushNotification = try propertiesContainer.decodeIfPresent(Bool.self, forKey: .nonPushNotification) ?? false + language = try propertiesContainer.decodeIfPresent(String.self, forKey: .language) ?? "en" userConsents = try propertiesContainer.decodeSafelyIfPresentArray(of: ConsentModel.self, forKey: .userConsents) ?? [] isPasswordSet = try propertiesContainer.decodeIfPresent(Bool.self, forKey: .isPasswordSet) ?? false