Reputation: 213
enum category: UInt32 {
case fence = 1
case paddle = 2
case block = 4
case ball = 8
}
struct category{
static var fence:UInt32 = 1
static var paddle:UInt32 = 2
static var block:UInt32 = 4
static var category:UInt32 = 8
}
trying to create a set of bitMasks, I am wondering which one is the proper way to do this.
enum or struct ?
Upvotes: 3
Views: 187
Reputation: 535860
What you want is an Option Set. That is Swift's way of letting you build a bitmask, such that you can then manipulate it like a set, which is really nice.
There's a fine example in the Swift docs:
Newer version here:
https://developer.apple.com/reference/swift/optionset
Upvotes: 2