Cannot convert value of type 'String' to expected argument type 'Double'

Hello the community, how are you?
I'm facing a new problem I cannot solve:

    let newBill = Bill(
        id: UUID().uuidString,
        name: billName,
        amount: billAmount, //Cannot convert value of type 'String' to expected argument type 'Double'
        currency: billCurrency,
        date: billDate,
        number: billNumber,
        company: billingCompany,
        paymentMethod: paymentMethod,
        recurrence: billRecurrence,
        alarmName: customAlarmURL?.lastPathComponent ?? (alarmNamesMapping[selectedAlarm ?? ""] ?? "None"),
        category: selectedCategory,
        isPaid: false,
        paymentDate: nil
    )

struct Bill: Identifiable, Codable {
var id: String
var name: String
var amount: Double
var currency: String
var date: Date
var number: String
var company: String
var paymentMethod: String
var recurrence: String
var alarmName: String
var category: String
var isPaid: Bool
var paymentDate: Date?

Here's my code shared, could you please help me to solve this part of the code?

All the best,

That variable is likely of the type String, you might want to either change that to Double or convert it via something like guard let amount = Double(billAmount) else { /*do something here*/ }

1 Like

Thanks a lot it worked :D