Type of expression is ambiguous without more context - Error Swift

func parseJSON(_ dosageData: Data) -> DoseModel? {
Code Block
do {
let json = try JSON(data: dosageData)
let date = json["date"].stringValue
let medicine = json["medicine"].stringValue
let units = json["units"].doubleValue
let value = json["value"].stringValue
let dose = DoseModel(id: UUID(), --- Error Line ----
date: date,
medicine: medicine,
units: units,
value: value)
return dose
} catch {
delegate?.didFailWithError(error: error)
return nil
}
}


struct DoseModel: Identifiable {
Code Block
var id: ObjectIdentifier
var date: String
var medicine: String
var units: String
var value: String

}


I keep getting the type error on this code. Any suggestions
Please make a better formatting to your code, start with ``` only line and end with ``` only line.


You declare the type of your first property id as ObjectIdentifier (which is rarely used), but passing an instance of UUID to it.
Try changing the definition of DoseModel as follows:
Code Block
struct DoseModel: Identifiable {
var id: UUID //<-
var date: String
var medicine: String
var units: Double //<- You use `doubleValue` for `value`
var value: String
}



By the way, what is JSON? I guess you are using an old third party framework which once was popular in ancient Swift developers.
But currently, it is considered to be a ruins of old era. You should better move to Codable.
Type of expression is ambiguous without more context - Error Swift
 
 
Q