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"]
}
}
Post
Replies
Boosts
Views
Activity
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.
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.
I'm working in a app that uses Apple Pay, and everything was working, but suddenly this crash start to happen
func startPaymentWith(output: PaymentHandlerResponseProtocol?) {
self.output = output
self.output?.startProcess()
// Create our payment request
let paymentRequest = PKPaymentRequest()
paymentRequest.paymentSummaryItems = paymentSummaryItems
paymentRequest.merchantIdentifier = "merchant.br.com.tim.appmeutim2"
paymentRequest.merchantCapabilities = .capability3DS
paymentRequest.countryCode = "BR"
paymentRequest.currencyCode = "BRL"
paymentRequest.supportedNetworks = self.supportedNetworks
print("comoestaovalorsemreplace \(paymentRequest.paymentSummaryItems[0].amount)")
// Display our payment request
paymentController = PKPaymentAuthorizationController(paymentRequest: paymentRequest) // Here happens the EXC_BAD_ACCESS
paymentController?.delegate = self
paymentController?.present(completion: { (presented: Bool) in
if presented {
debugPrint("Presented payment controller")
} else {
debugPrint("Failed to present payment controller")
self.output?.responseWith(nil)
}
})
}
This is showed in var paymentRequest when is hover the mouse pointer above the variable:
expression produced error: error:
/var/folders/sp/8x6rp88s4nv6s3z1635pqdtm0000gq/T/expr139-c248cd..swift:1:65:
error: cannot find type 'PassKit' in scope
Swift._DebuggerSupport.stringForPrintObject(Swift.UnsafePointer<PassKit.PKPaymentRequest>(bitPattern:
0x15e4e9da0)!.pointee)