penatheboss penatheboss - 1 month ago 24
Swift Question

Use of unresolved operator <=

I am trying to use Swift 3 for-loops, but I have been unsuccessful. Here is what I have:

for assumedPayRate: Double in (0.25..<=billRate) where assumedPayRate += 0.25 {


On the
..<=
it gives me the error:


Use of unresolved operator '..<='


Here is the original Swift 2 version:

for var assumedPayRate:Double = 0.25; assumedPayRate <= billRate; assumedPayRate += 0.25 {


How can I fix this error?

Answer

The operator ..<= doesn't exist in Swift and your syntax is invalid. Use stride instead:

// Assuming billRate is a Double
for assumedPayRate in stride(from: 0.25, through: billRate, by: 0.25) {
    // Do your things
}