Post

Replies

Boosts

Views

Activity

What is wrong with this Model ?
I'm taking a response from an API and using below model, but I'm getting an error ObjectMapper fail to serialize response, what is wrong with the model ? import ObjectMapper // MARK: - RealTimeSummary class RealTimeSummary: Mappable { var realTimeSummaryReturn: ReturnRealTime = ReturnRealTime() var success: Bool = false required convenience init?(map: Map) { self.init() self.mapping(map: map) } func mapping(map: Map) { realTimeSummaryReturn <- map["Return"] success <- map["Success"] } } // MARK: - Return class ReturnRealTime: Mappable { var summary: Summary = Summary() var accounts: [AccountRealTime] = [] init(){} required convenience init?(map: Map) { self.init() self.mapping(map: map) } func mapping(map: Map) { summary <- map["Summary"] accounts <- map["Accounts"] } } // MARK: - Account class AccountRealTime: Mappable { var accountType: String = "" var accountNumber: String = "" var accountDescription: String = "" var accountProductCode: String = "" var availableBalance: Double = 0.0 var currentBalance: Int = 0 var holdAmount: Int = 0 init(){} required convenience init?(map: Map) { self.init() self.mapping(map: map) } func mapping(map: Map) { accountType <- map["AccountType"] accountNumber <- map["AccountNumber"] accountDescription <- map["AccountDescription"] accountProductCode <- map["AccountProductCode"] availableBalance <- map["AvailableBalance"] currentBalance <- map["CurrentBalance"] holdAmount <- map["HoldAmount"] } } // MARK: - Summary class Summary: Mappable { var availableBalanceTotal: Double = 0.0 var currentBalanceTotal: Int = 0 init(){} required convenience init?(map: Map) { self.init() self.mapping(map: map) } func mapping(map: Map) { availableBalanceTotal <- map["AvailableBalanceTotal"] currentBalanceTotal <- map["CurrentBalanceTotal"] } }
2
0
858
Jul ’23
How to Migrate iOS Aplication api
I'm from a development team at a large Telecom, I'm migrating an API within an app, the new version of the api will have a completely new model, with a new structure, the data coming from the api is recorded in the coredata and then extracted from this to be displayed by the viewcontroller (cashe), the client asked to do it in stages, and the first stage is to migrate to the next api to deliver value quickly, I am in doubt if I implement the entire model at this first moment, having to change the entire structure that extracts the model from coredata to display, or if I just create a mapping from the new model to the old one (mapping the new values to the old ones), just to record the data, maintaining the structure of extracting data from coredata and display, leaving this to be removed in a next step. Which of the two ways will take more work? Changing the model and also the recording and extracting structure will be much more costly, which will extend the work to unacceptable deadlines? One of the goals is to completely remove the CoreData. I'm in the process of renaming all the fields, changing the model's structure and the model's recording and extraction flows, but I'm thinking that this work will be huge, not having any value delivery in the short term.
3
0
920
Feb ’23
Swift codable: an object that is come from an API, changed from type Array to Object
An API changed its JSON, a field named contactMedium, that was coming in form of a Array changed to an Object: was like this : { "contactMedium": [         {             "type": "EMAIL",             "characteristic": {                 "emailAddress": "ibenedit"             }         }     ], } become like this : { "contactMedium": {         "characteristics": {             "emailAddress": "ibeneditobr"         },         "type": "EMAIL"     }, } My question is, how I implement the init's struct ("init(from decoder: Decoder) throws {") , to convert from object to Array ? In my struct I tried to change: from : public var contactMedium: [ContactMedium]? to : public var contactMedium: ContactMedium? But app crashes in various places, because of use the array's methods like filter.
2
0
959
Dec ’22
What is wrong with this Model ?
I'm taking a response from an API and using below model, but I'm getting an error ObjectMapper fail to serialize response, what is wrong with the model ? import ObjectMapper // MARK: - RealTimeSummary class RealTimeSummary: Mappable { var realTimeSummaryReturn: ReturnRealTime = ReturnRealTime() var success: Bool = false required convenience init?(map: Map) { self.init() self.mapping(map: map) } func mapping(map: Map) { realTimeSummaryReturn <- map["Return"] success <- map["Success"] } } // MARK: - Return class ReturnRealTime: Mappable { var summary: Summary = Summary() var accounts: [AccountRealTime] = [] init(){} required convenience init?(map: Map) { self.init() self.mapping(map: map) } func mapping(map: Map) { summary <- map["Summary"] accounts <- map["Accounts"] } } // MARK: - Account class AccountRealTime: Mappable { var accountType: String = "" var accountNumber: String = "" var accountDescription: String = "" var accountProductCode: String = "" var availableBalance: Double = 0.0 var currentBalance: Int = 0 var holdAmount: Int = 0 init(){} required convenience init?(map: Map) { self.init() self.mapping(map: map) } func mapping(map: Map) { accountType <- map["AccountType"] accountNumber <- map["AccountNumber"] accountDescription <- map["AccountDescription"] accountProductCode <- map["AccountProductCode"] availableBalance <- map["AvailableBalance"] currentBalance <- map["CurrentBalance"] holdAmount <- map["HoldAmount"] } } // MARK: - Summary class Summary: Mappable { var availableBalanceTotal: Double = 0.0 var currentBalanceTotal: Int = 0 init(){} required convenience init?(map: Map) { self.init() self.mapping(map: map) } func mapping(map: Map) { availableBalanceTotal <- map["AvailableBalanceTotal"] currentBalanceTotal <- map["CurrentBalanceTotal"] } }
Replies
2
Boosts
0
Views
858
Activity
Jul ’23
How to Migrate iOS Aplication api
I'm from a development team at a large Telecom, I'm migrating an API within an app, the new version of the api will have a completely new model, with a new structure, the data coming from the api is recorded in the coredata and then extracted from this to be displayed by the viewcontroller (cashe), the client asked to do it in stages, and the first stage is to migrate to the next api to deliver value quickly, I am in doubt if I implement the entire model at this first moment, having to change the entire structure that extracts the model from coredata to display, or if I just create a mapping from the new model to the old one (mapping the new values to the old ones), just to record the data, maintaining the structure of extracting data from coredata and display, leaving this to be removed in a next step. Which of the two ways will take more work? Changing the model and also the recording and extracting structure will be much more costly, which will extend the work to unacceptable deadlines? One of the goals is to completely remove the CoreData. I'm in the process of renaming all the fields, changing the model's structure and the model's recording and extraction flows, but I'm thinking that this work will be huge, not having any value delivery in the short term.
Replies
3
Boosts
0
Views
920
Activity
Feb ’23
Swift codable: an object that is come from an API, changed from type Array to Object
An API changed its JSON, a field named contactMedium, that was coming in form of a Array changed to an Object: was like this : { "contactMedium": [         {             "type": "EMAIL",             "characteristic": {                 "emailAddress": "ibenedit"             }         }     ], } become like this : { "contactMedium": {         "characteristics": {             "emailAddress": "ibeneditobr"         },         "type": "EMAIL"     }, } My question is, how I implement the init's struct ("init(from decoder: Decoder) throws {") , to convert from object to Array ? In my struct I tried to change: from : public var contactMedium: [ContactMedium]? to : public var contactMedium: ContactMedium? But app crashes in various places, because of use the array's methods like filter.
Replies
2
Boosts
0
Views
959
Activity
Dec ’22