An open API service indexing awesome lists of open source software.

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`.

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``