Friday, May 1, 2026
HomeiOS Developmentios - Learn how to convert for-in loop into foreach in Swift?

ios – Learn how to convert for-in loop into foreach in Swift?

[ad_1]

I’ve one for loop the place I discovered index in repeating therefore I need to convert into foreach loop.

for (key, _) in particulars {
    let product = product
    particulars[key]?.title = product.first?.identify ?? ""
    particulars[key]?.quantity = Double(product.first?.costs ?? 0.0)
} 

I attempted this as under however nonetheless right here particulars[key]? is repeating

particulars.forEach { key, worth in
   let product = product
   particulars[key]?.title = cartProduct.first?.identify ?? ""
   particulars[key]?.quantity = Double(product.first?.costs ?? 0.0)
}

Might I do know, the right way to convert this into foreach in Swift in order that I need not write [key] every-time.

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments