This code has no syntax error.
for (var m = 1.0; m < 3.0; m += 0.1) {
}
On the other hand, the below code has an syntax error. Error Message: Binary operator '<' cannot be applied to operands of type 'Double' and 'CGFloat'
let image = UIImage(named: "myImage")
for (var n = 1.0; n < image!.size.height; n += 0.1) {
}
Why it happend? I tried to use if let instead of force unwrap, but I had the same error.
Environment: Xcode7.0.1 Swift2
Because image!.size.height return CGFloat any type of your n is Double so you need to convert your CGFloat to Double this way Double(image!.size.height).
And your code will be:
let image = UIImage(named: "myImage")
for (var n = 1.0; n < Double(image!.size.height); n += 0.1) {
}
Or you can assign type to n as CGFloat this way:
for (var n : CGFloat = 1.0; n < image!.size.height; n += 0.1) {
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With