{"id":19233676,"url":"https://github.com/brightdigit/options","last_synced_at":"2025-10-26T05:04:00.194Z","repository":{"id":53122224,"uuid":"353159594","full_name":"brightdigit/Options","owner":"brightdigit","description":"Sometimes there are situations where you want to use an Enum in an OptionSet or you want Enum backed by a RawType of Int but also have String labels as well","archived":false,"fork":false,"pushed_at":"2025-06-17T21:10:04.000Z","size":155,"stargazers_count":21,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-08-12T08:15:40.840Z","etag":null,"topics":["bitflags","codable","enum","optionset","swift"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/brightdigit.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2021-03-30T22:40:41.000Z","updated_at":"2025-03-09T11:57:11.000Z","dependencies_parsed_at":"2025-04-21T04:51:08.737Z","dependency_job_id":null,"html_url":"https://github.com/brightdigit/Options","commit_stats":{"total_commits":6,"total_committers":1,"mean_commits":6.0,"dds":0.0,"last_synced_commit":"36642d1d6b8e7a41406c68538b6714889c2024ce"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/brightdigit/Options","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brightdigit%2FOptions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brightdigit%2FOptions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brightdigit%2FOptions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brightdigit%2FOptions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/brightdigit","download_url":"https://codeload.github.com/brightdigit/Options/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brightdigit%2FOptions/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272498344,"owners_count":24944820,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-28T02:00:10.768Z","response_time":74,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bitflags","codable","enum","optionset","swift"],"created_at":"2024-11-09T16:11:29.312Z","updated_at":"2025-10-26T05:03:55.161Z","avatar_url":"https://github.com/brightdigit.png","language":"Swift","readme":"\n\u003cp align=\"center\"\u003e\n    \u003cimg alt=\"Options\" title=\"Options\" src=\"logo.png\" height=\"200\"\u003e\n\u003c/p\u003e\n\u003ch1 align=\"center\"\u003e Options \u003c/h1\u003e\n\nMore powerful options for `Enum` and `OptionSet` types.\n\n[![SwiftPM](https://img.shields.io/badge/SPM-Linux%20%7C%20iOS%20%7C%20macOS%20%7C%20watchOS%20%7C%20tvOS-success?logo=swift)](https://swift.org)\n[![Twitter](https://img.shields.io/badge/twitter-@brightdigit-blue.svg?style=flat)](http://twitter.com/brightdigit)\n![GitHub](https://img.shields.io/github/license/brightdigit/Options)\n![GitHub issues](https://img.shields.io/github/issues/brightdigit/Options)\n![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/brightdigit/Options/Options.yml?label=actions\u0026logo=github\u0026?branch=main)\n\n[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fbrightdigit%2FOptions%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/brightdigit/Options)\n[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fbrightdigit%2FOptions%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/brightdigit/Options)\n\n[![Codecov](https://img.shields.io/codecov/c/github/brightdigit/Options)](https://codecov.io/gh/brightdigit/Options)\n[![CodeFactor Grade](https://img.shields.io/codefactor/grade/github/brightdigit/Options)](https://www.codefactor.io/repository/github/brightdigit/Options)\n[![codebeat badge](https://codebeat.co/badges/c47b7e58-867c-410b-80c5-57e10140ba0f)](https://codebeat.co/projects/github-com-brightdigit-mistkit-main)\n[![Code Climate maintainability](https://img.shields.io/codeclimate/maintainability/brightdigit/Options)](https://codeclimate.com/github/brightdigit/Options)\n[![Code Climate technical debt](https://img.shields.io/codeclimate/tech-debt/brightdigit/Options?label=debt)](https://codeclimate.com/github/brightdigit/Options)\n[![Code Climate issues](https://img.shields.io/codeclimate/issues/brightdigit/Options)](https://codeclimate.com/github/brightdigit/Options)\n[![Reviewed by Hound](https://img.shields.io/badge/Reviewed_by-Hound-8E64B0.svg)](https://houndci.com)\n\n\n# Table of Contents\n\n  * [Introduction](#introduction)\n  * [Requirements](#requirements)\n  * [Installation](#installation)\n  * [Usage](#usage)\n    * [Versatile Options with Enums and OptionSets](#versatile-options-with-enums-and-optionsets)\n    * [Multiple Value Types](#multiple-value-types)\n    * [Creating an OptionSet](#creating-an-optionset)\n  * [Further Code Documentation](#further-code-documentation)\n  * [License](#license)\n\n# Introduction\n\n**Options** provides a powerful set of features for `Enum` and `OptionSet` types:\n\n- Providing additional representations for `Enum` types besides the `RawType rawValue` \n- Being able to interchange between `Enum` and `OptionSet` types\n- Using an additional value type for a `Codable` `OptionSet`\n\n# Requirements \n\n**Apple Platforms**\n\n- Xcode 14.1 or later\n- Swift 5.7.1 or later\n- iOS 16 / watchOS 9 / tvOS 16 / macOS 12 or later deployment targets\n\n**Linux**\n\n- Ubuntu 20.04 or later\n- Swift 5.7.1 or later\n\n# Installation\n\nUse the Swift Package Manager to install this library via the repository url:\n\n```\nhttps://github.com/brightdigit/Options.git\n```\n\nUse version up to `1.0`.\n\n# Usage \n\n## Versatile Options\n\nLet's say we are using an `Enum` for a list of popular social media networks:\n\n```swift\nenum SocialNetwork : Int {\n  case digg\n  case aim\n  case bebo\n  case delicious\n  case eworld\n  case googleplus\n  case itunesping\n  case jaiku\n  case miiverse\n  case musically\n  case orkut\n  case posterous\n  case stumbleupon\n  case windowslive\n  case yahoo\n}\n```\n\nWe'll be using this as a way to define a particular social handle:\n\n```swift\nstruct SocialHandle {\n  let name : String\n  let network : SocialNetwork\n}\n```\n\nHowever we also want to provide a way to have a unique set of social networks available:\n\n```swift\nstruct SocialNetworkSet : Int, OptionSet {\n...\n}\n\nlet user : User\nlet networks : SocialNetworkSet = user.availableNetworks()\n```\n\nWe can then simply use ``Options()`` macro to generate both these types:\n\n```swift\n@Options\nenum SocialNetwork : Int {\n  case digg\n  case aim\n  case bebo\n  case delicious\n  case eworld\n  case googleplus\n  case itunesping\n  case jaiku\n  case miiverse\n  case musically\n  case orkut\n  case posterous\n  case stumbleupon\n  case windowslive\n  case yahoo\n}\n```\n\nNow we can use the newly create `SocialNetworkSet` type to store a set of values:\n\n```swift\nlet networks : SocialNetworkSet\nnetworks = [.aim, .delicious, .googleplus, .windowslive]\n```\n\n## Multiple Value Types\n\nWith the ``Options()`` macro, we add the ability to encode and decode values not only from their raw value but also from a another type such as a string. This is useful for when you want to store the values in JSON format.\n\nFor instance, with a type like `SocialNetwork` we need need to store the value as an Integer:\n\n```json\n5\n```\n\nHowever by adding the ``Options()`` macro we can also decode from a String:\n\n```\n\"googleplus\"\n```\n\n## Creating an OptionSet\n\nWe can also have a new `OptionSet` type created. ``Options()`` create a new `OptionSet` type with the suffix `-Set`. This new `OptionSet` will automatically work with your enum to create a distinct set of values. Additionally it will decode and encode your values as an Array of String. This means the value:\n\n```swift\n[.aim, .delicious, .googleplus, .windowslive]\n```\n\nis encoded as:\n\n```json\n[\"aim\", \"delicious\", \"googleplus\", \"windowslive\"]\n```\n\n# Further Code Documentation\n\n[Documentation Here](https://swiftpackageindex.com/brightdigit/Options/main/documentation/options)\n\n# License \n\nThis code is distributed under the MIT license. See the [LICENSE](LICENSE) file for more info.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrightdigit%2Foptions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrightdigit%2Foptions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrightdigit%2Foptions/lists"}