I wanted to make some part of my app offline as the my client requested it. I've been racking my brain on making my structure codable so that I can save the data to user defaults, but I always get this error
Type 'BookingDataModel' does not conform to protocol 'Decodable'
Here is my BookingDataModal:
struct BookingDataModel: Codable {
static var shared = BookingDataModel()
var collaps = false
var _id = ""
var userId = ""
var venderName = ""
var created_at = ""
var transaction_id = ""
var payment_method = ""
var updated_at = ""
var booking_confirmed = false
var booking_status = ""
var payment_status = false
var type = ""
var isCanceledRequest: Bool?
var flight: [FlightBookingDataModel]?
var newFlight: (departure: [FlightBookingDataModel], return: [FlightBookingDataModel])?
var event: HotelBookingDataModel?
var hotel: NewHotelBookingDataModel?//HotelBookingDataModel?
var isAxaPolicy = false
var relationshipId = ""
var passengers = [UsersModel]()
var total = 0.0
var tacCoinDiscount: Int?
var couponDiscount: Int?
var afterDiscountAmount: Int?
func getBookingDataModel(arr: NSArray, type: String) -> [BookingDataModel] {
// save data from API
}
}
At first I thought my other modals were not codable, so I made them all Codable, and it still would throw the same error Here is the FlightBookingDataModal :
struct FlightBookingDataModel: Codable {
static var shared = FlightBookingDataModel()
var pnrData = PNRDataModel()
var src_name = ""
var dst_name = ""
var srcCode = ""
var dstCode = ""
var atime_utc = String()
var dtime_utc = String()
var atime = String()
var dtime = String()
var flight_no = ""
var checkin = ""
var price = 0.0
var airLineName = ""
var eticket_link = ""
var invoice = ""
var isReturnFlight = false
func getFlightBookigDataModel(dict: NSDictionary) -> [FlightBookingDataModel] {
// Save data from API
}
}
PNR Modal :
class PNRDataModel: Codable {
var src = ""
var dst = ""
var iata = ""
var pnr = ""
}
HotelBookingDataModel :
struct HotelBookingDataModel: Codable {
var cityName = ""
var name = ""
var address = ""
var startOfServiceTime = ""
var endOfServiceTime = ""
var aetherReference = ""
var provider = ""
var reference = ""
var price = 0.0
var date = ""
var reservationId = ""
}
NewHotelBookingDataModel:
struct NewHotelBookingDataModel: Codable {
var name = ""
var address = ""
var cityName = ""
var price = 0.0
var reference = ""
var provider = "" //not found in new response
var startOfServiceTime = ""
var endOfServiceTime = ""
var aetherReference = ""
}
If anyone can give me any insights as why is this not working, that would help me a lot. I just want to save [BookingDataModal] offline for a limited time until the user comes back online.
The reason of the error is the property newFlight
in BookingDataModel
.
Codable
does not support tuples.