Reputation: 1311
It seems that bitwise operators don't work with UInt64 variables in Swift.
class Polyomino {
var squares : UInt64 = 0
var xLength : UInt8 = 0
var yLength : UInt8 = 0
func addSquareAt(x : UInt8, y : UInt8) {
squares |= (UInt64(1) << (x + y * 8))
}
}
The line with the bitwise operator gives the error "could not fin overload for "\=" with the supplied arguments". The same thing goes with the following statement:
squares = squares | (UInt64(1) << (x + y * 8))
I'm assuming this is an error on Apple's part (could be wrong) but is there any way to fix this temporarily or should I just wait for Apple for a fix? Or maybe I'm doing something wrong?
Upvotes: 2
Views: 1699
Reputation: 93276
The type safety in Swift means that you can't do operations between different numeric types. You're trying to shift UInt8
s against a UInt64
, which isn't supported. Try casting the result to UInt64
instead:
func addSquareAt(x : UInt8, y : UInt8) {
squares |= 1 << UInt64(x + y * 8)
}
Upvotes: 3