I have the following data class which I have tried adding an array of AdditionalCharge to but get the error specified in the title.
The AdditionalCharge class and the FundingRequest class containing the additional charge is below.
I'm not sure what I've done wrong.
class AdditionalCharge{
var ItemDescription = ""
var ItemValue:String = ""
}
class FundingRequest: Codable {
let dispatcherName, loadReference, origin, destination: String
let userID: String, applicationID: String
let pickedUp, droppedOff: String
let driverFirstName, driverLastName: String
let grossTruckPay,fundingMethod, comments: String
let advancesTaken: Bool
let rateConfirmation, billOfLading, lumperReceipt: [String]
let salesTicket: [String]
let debtorID: String
let additionalCharges = [AdditionalCharge]()
enum CodingKeys: String, CodingKey {
case dispatcherName = "DispatcherName"
case loadReference = "LoadReference"
case origin = "Origin"
case destination = "Destination"
case userID = "UserID"
case applicationID = "ApplicationID"
case pickedUp = "PickedUp"
case droppedOff = "DroppedOff"
case driverFirstName = "DriverFirstName"
case driverLastName = "DriverLastName"
case grossTruckPay = "GrossTruckPay"
case advancesTaken = "AdvancesTaken"
case fundingMethod = "FundingMethod"
case comments = "Comments"
case additionalCharges = "AdditionalCharges"
case rateConfirmation = "RateConfirmation"
case billOfLading = "BillOfLading"
case lumperReceipt = "LumperReceipt"
case salesTicket = "SalesTicket"
case debtorID = "DebtorID"
}
init(dispatcherName: String, loadReference: String, origin: String, destination: String, userID: String,applicationID: String, pickedUp: String, droppedOff: String, driverFirstName: String, driverLastName: String, grossTruckPay: String, advancesTaken: Bool, fundingMethod: String, comments: String, additionalCharges: [AdditionalCharge], rateConfirmation: [String], billOfLading: [String], lumperReceipt: [String], salesTicket: [String], debtorID:String) {
self.dispatcherName = dispatcherName
self.loadReference = loadReference
self.origin = origin
self.destination = destination
self.userID = userID
self.pickedUp = pickedUp
self.droppedOff = droppedOff
self.driverFirstName = driverFirstName
self.driverLastName = driverLastName
self.grossTruckPay = grossTruckPay
self.advancesTaken = advancesTaken
self.fundingMethod = fundingMethod
self.comments = comments
self.additionalCharges = additionalCharges
self.rateConfirmation = rateConfirmation
self.billOfLading = billOfLading
self.lumperReceipt = lumperReceipt
self.salesTicket = salesTicket
self.debtorID = debtorID
self.applicationID = applicationID
}
Every property in a Codable
type must also be Codable
as well.
The simplest way to make a type codable is to declare its properties using types that are already Codable.
Built-in Codable types — String, Int, Double, Data, URL Array,
Dictionary, Optional are Codable if they contain Codable types
Hence, the AdditionalCharge
must also be Codable
for FundingRequest
to be Codable
.
class AdditionalCharge: Codable {
var ItemDescription = ""
var ItemValue:String = ""
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With