Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to define category bit mask enumeration for SpriteKit in Swift?

To define a category bit mask enum in Objective-C I used to type:

typedef NS_OPTIONS(NSUInteger, CollisionCategory) {     CollisionCategoryPlayerSpaceship = 0,     CollisionCategoryEnemySpaceship = 1 << 0,     CollisionCategoryChickenSpaceship = 1 << 1, }; 

How can I achieve the same using Swift? I experimented with enums but can't get it working. Here is what I tried so far.

error screenshot

like image 786
Rafa de King Avatar asked Jun 05 '14 20:06

Rafa de King


1 Answers

What you could do is use the binary literals: 0b1, 0b10, 0b100, etc.

However, in Swift you cannot bitwise-OR enums, so there is really no point in using bitmasks in enums. Check out this question for a replacement for NS_OPTION.

like image 83
nschum Avatar answered Sep 30 '22 20:09

nschum