Hunter Hunter - 3 months ago 12
Swift Question

Binary operator '==' cannot be applied to operands of type 'UInt32' and 'Int'

Hey Im trying to create a didBeginContact func and I can't get passed this. Also know other question on here looks remotely like this. But I'm guessing its a simple fix. Any Help? The picture below has the error.

enter image description here
enter image description here
Code:

//Collision bit masks
let BitmaskCollision = 1 << 2
let BitmaskCollision2 = 1 << 3
let BitmaskCollision3 = 1 << 4
let gravityFieldCategory = 1 << 5
let BitmaskOutofBounds = 1 << 6



func didBeginContact(contact: SKPhysicsContact) {
if contact.bodyA.categoryBitMask == BitmaskCollision||contact.bodyB.categoryBitMask == BitmaskCollision {
print("I know im hitting it")
}
}

Answer

Binary operator '==' cannot be applied to operands of type 'UInt32' and 'Int'

This is because there is a type mismatch between the operands. BitmaskCollision is of type Int, contact.bodyA.categoryBitMask would be of type Int32. Make it same type would work

 if Int(contact.bodyA.categoryBitMask) == BitmaskCollision{
}
Comments