How would I construct an OptionSetType with a raw value greater than 64 bit shifts (i.e. Int64) that is still able to be encoded using NSCoder? I have more than 64 potential bitwise options to combine.
Bit field larger than 64 shifts in Swift?
1.6k Views Asked by rolling_codes At
2
There are 2 best solutions below
5
On
Disclaimer: I never tried
I suppose you can build your own Int128.
E.g. this library defined a UInt256 type.
Once you have your new type you can simply use it with OptionSetType I guess.
struct YourOptions : OptionSetType{
let rawValue : Int128
init(rawValue:Int128) {
self.rawValue = rawValue
}
}
So I eventually had to create my own primitive
structwhich was a pain in the ass, since the library @appzYourLife provided does not actually meet every protocol required ofUnsignedIntegerTypes. The following is an extension I wrote that actually allows me to write things likewhich would output to the console:
The extension is pretty lengthy and does not yet implement multiplication and devision or bit-shifting numbers other than
1. This version also supports encoding with andNSCoder