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 ?
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:
https://developer.apple.com/library/ios/documentation/Swift/Reference/Swift_OptionSetType_Protocol/index.html
Newer version here:
https://developer.apple.com/reference/swift/optionset
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With