https://github.com/romainroche/swift-bitmask
This Swift Package is an alternative to Swift `OptionSet` to make bitmask operations with `Enum`.
https://github.com/romainroche/swift-bitmask
bitmask ios swift
Last synced: 12 months ago
JSON representation
This Swift Package is an alternative to Swift `OptionSet` to make bitmask operations with `Enum`.
- Host: GitHub
- URL: https://github.com/romainroche/swift-bitmask
- Owner: RomainRoche
- Created: 2021-12-17T08:44:22.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2021-12-24T08:34:26.000Z (over 4 years ago)
- Last Synced: 2025-03-14T17:11:17.406Z (over 1 year ago)
- Topics: bitmask, ios, swift
- Language: Swift
- Homepage:
- Size: 27.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# ``bitmask``
This framework is an alternative to the native ``OptionSet`` structure. It is intended to make `bitmask` operations using `Enum`.
## Example
```swift
import Bitmask
enum Subscription: Int, Maskable {
case none = 0b0
case comedy = 0b1
case action = 0b10
case romance = 0b100
}
// create a Bitmask
var subscriptions = Bitmask(with: .none)
// subscribe to `.comedy` and `.action`
subscription = subscription | .comedy
subscription = subscription | .action
// is subscribed to `.action`? -> true
let romanceSubscribed = subscription &? .action
// is subscribed to `.romance`? -> false
let romanceSubscribed = subscription &? .romance
// unsubscribe to `.comedy`
subscription = subscription &~ .comedy
```
## Installation
### Swift Package Manager
Add this repository as a **Swift Package**.
``https://github.com/RomainRoche/swift-bitmask``