ios - Bitwise AND operation on UInt8 enum -
having next enumeration
enum collidertype: uint8 { case hero = 0b1 case goblinorboss = 0b10 case projectile = 0b100 case wall = 0b1000 case cave = 0b10000 }
i'm trying simple:
allow combined = collidertype.hero.toraw() | collidertype.wall.toraw() // test 'combined' 'wall' bitmask if (combined & collidertype.wall.toraw()) { // compliation error :[ }
the error i'm getting follows
type 'uint8' not conform protocol 'booleantype'
it's because combined & collidertype.wall.toraw()
returns uint8
while if
expecting booleantype
.
if (combined & collidertype.wall.toraw()) != 0 { }
should work.
ios swift bitmask
No comments:
Post a Comment