Given the following function:
func greatestCommonDenominator(first: Int, second: Int) -> Int {
return second == 0 ? first : greatestCommonDenominator(second, first % second)
}
And a structure in which there are the following things:
struct Fraction {
var numerator: Int
var denominator: Int
func reduce() {
let gcd = greatestCommonDenominator(numerator,denominator)
self.numerator /= gcd
self.denominator /= gcd
}
}
I get the following error:
error: 'Int' is not convertible to '@lvalue Float'
self.numerator /= gcd
^
error: 'Int' is not convertible to '@lvalue Float'
self.denominator /= gcd
^
'@lvalue Float'?!?!? What kind? I don't have a float anywhere here. And the documentation seems to suggest that it /=should return Intas I am sharing two Ints. How to fix it?
APPENDIX: I came across this problem working inside the structure, however the problem seems to be reproducible anywhere.
let a = 10
a /= 5
This will cause the same problem. Even if we explicitly type aas Int:
let a: Int = 10
a /= 5
The same problems remain. Swift seems to think that the result of the statement /=between two Ints is Float.
EDIT: , a /= 5 . !
var a: Int = 4
var b: Int = 3
a /= b
a 3. . a let, a var, .