Quick warning - integer overflows when converting from 'Builtin.Int32' to 'Builtin.Int8'
I am getting the following warning without referencing the line where it happens:
warning: integer overflows when converted from 'Builtin.Int32' to 'Builtin.Int8'
The warning occurs 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 accepts Int, so I don't immediately know why that would be - any ideas?
+3
source to share
1 answer
This looks like an error and is caused by a method description
in your method ToString()
. The same warning is already happening with
let x = CGFloat(12.0)
let s = x.description
As a workaround, you can use string interpolation:
func ToString() -> String {
return "(\(self.x),\(self.y))"
}
or simply
func ToString() -> String {
return "\(self)"
}
which gives the same result.
+5
source to share