Initializer for conditional binding must have Optional type, not 'String'

Hello again eveybody,

I have another problem on my view. It is about 200 lines long. I have the same problem each time I write " guard let billId = bill.id else {"
The problem is the following: Initializer for conditional binding must have Optional type, not 'String'

Here's some examples where we find this line:

            func updatePaymentDateForBill(bill: Bill, paymentDate: Date) {
                guard let userID = Auth.auth().currentUser?.uid else { return }
                guard let billId = bill.id else {
                    print("❌ ID de facture manquant.")
                    return
                }
            func markBillAsUnpaid(bill: Bill) {
                guard let userID = Auth.auth().currentUser?.uid else { return }
                guard let billId = bill.id else {
                    print("❌ ID de facture manquant.")
                    return
                }

If you find the solution you are my God :stuck_out_tongue:

All the best,

Bill.id is not optional. Why are you trying to use guard on it?

Also, why are you binding billId at all, if you're not going to use it?

1 Like

This might have some ideas if you are new to Swift:

1 Like

Hello Danny, how are you? Yes, you're right, I've fixed it and now it works :slight_smile: many thanks

1 Like

Thanks for the link!

1 Like