Reputation: 7219
I am getting the following warning, with no reference to the line in which it is happening:
warning: integer overflows when converted from 'Builtin.Int32' to 'Builtin.Int8'
The warning arises in this code:
extension NSPoint {
func ToString() -> String {
return "(" + self.x.description + "," + self.y.description + ")"
}
func Plus(toBeAdded : NSPoint) -> NSPoint {
return NSPoint(x: self.x + toBeAdded.x, y: self.y + toBeAdded.y)
}
func Minus(toBeMinused : NSPoint) -> NSPoint {
return NSPoint(x: self.x - toBeMinused.x, y: self.y - toBeMinused.y)
}
static func fromScalar(scalar : Int) -> NSPoint {
return NSPoint(x: scalar, y: scalar)
}
}
The NSPoint initializer takes Int, so I don't immediately know why it would be this - any ideas?
Upvotes: 3
Views: 625
Reputation: 539835
This looks like a bug, and is caused by the description
method
in your ToString()
method. The same warning already occurs with
let x = CGFloat(12.0)
let s = x.description
As a workaround, you can use string interpolation instead:
func ToString() -> String {
return "(\(self.x),\(self.y))"
}
or just
func ToString() -> String {
return "\(self)"
}
which gives the same result.
Upvotes: 5