I am having the same problem as earlier with a different line of code; but this time, I wasn't able to fix it with the same approach as last time:
var Y : Int = 0
var X : Int = 0
@IBOutlet var ball : UIImageView!
ball.center = CGPointMake(ball.center.x + X, ball.center.y + Y)
This is the error I am getting:
binary operator + cannot be applied to operands of type CGfloat int
ball.center.x is a CGFloat and X is an Int. That's where the compiler is complaining.
Swift likes you to type cast numeric types (as if there wasn't a hierarchy in numeric domains) but you can avoid that by declaring X and Y as CGFloat instead of Int.
You could also get rid of the issue for good by defining the operator (that Swift should already have imho):
The problem is that you are not having the same variable types, for example you can't add bool and string.
Change it to CGFloat instead of int:
Declare them, instead, as the following:
Replying to your comment:
The error has nothing to do with them being declared as
var
orlet
. You could declare them asvar
and if you so insist on declaring them asInt
, you would still need to do the following: