{"id":18465912,"url":"https://github.com/edonv/orother","last_synced_at":"2026-02-09T09:33:53.398Z","repository":{"id":223955699,"uuid":"762009168","full_name":"edonv/OrOther","owner":"edonv","description":"A macro for adding a blank \"other\" case to any enum.","archived":false,"fork":false,"pushed_at":"2024-07-13T16:02:53.000Z","size":35,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-06T17:51:40.300Z","etag":null,"topics":["enum","macro","other","swift","xcode"],"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/edonv.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},"funding":{"github":"edonv"}},"created_at":"2024-02-22T22:47:36.000Z","updated_at":"2024-07-13T16:02:57.000Z","dependencies_parsed_at":null,"dependency_job_id":"c489607d-38a5-4248-bd42-6a9e9be86c1d","html_url":"https://github.com/edonv/OrOther","commit_stats":null,"previous_names":["edonv/orother"],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edonv%2FOrOther","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edonv%2FOrOther/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edonv%2FOrOther/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edonv%2FOrOther/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/edonv","download_url":"https://codeload.github.com/edonv/OrOther/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243020609,"owners_count":20223057,"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","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":["enum","macro","other","swift","xcode"],"created_at":"2024-11-06T09:14:28.298Z","updated_at":"2026-02-09T09:33:50.843Z","avatar_url":"https://github.com/edonv.png","language":"Swift","funding_links":["https://github.com/sponsors/edonv"],"categories":[],"sub_categories":[],"readme":"# OrOther\n\n[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fedonv%2FOrOther%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/edonv/OrOther)\n[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fedonv%2FOrOther%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/edonv/OrOther)\n\n`OrOther` is a macro that adds a \"blank\" `.other(_:)` case to any enum. All that's needed is to create an empty enum, add a `private` nested enum called `Options` with an explicit raw value type, add the explicit cases you want, then tack `@OrOther` onto the primary enum.\n\n`OrOther` will automatically synthesize the any enum cases you add to `Options`, then add an extra `.other(_:)` case. The `.other(_:)` case has an associated value of the same type as the `Options` enum's raw value.\n\nIt also automatically synthesizes conformace to `RawRepresentable` for the attached enum, by adding a synthesized computed `rawValue` property and `init(rawValue:)` initializer:\n- `rawValue` returns the `rawValue` of the matching case from the nested `Options` enum, unless it's `.other`, in which case, the associated value is returned.\n- `init(rawValue:)` is *non-failable*, as it first tries to match the `rawValue` to that of the `Options` enum and return the matching case. If there isn't a matching case in `Options`, it returns `rawValue` as the associated value of an `.other` case.\n\nYou can then add other protocols to your primary enum as you'd like (e.g. adding `Codable` to `EnumTest` in the example below).\n\nAdditionally, due to macros not being able to add an extension for a `private` type, you cannot make the primary enum `private`. The only workaround as of now is to explictly conform the primary enum to `RawRepresentable`.\n\n## Example\n\n### Usage\n\n```swift\n@OrOther\nenum EnumTest: Codable {\n    private enum Options: String {\n        case a\n        case b\n        case c, d, e, f\n    }\n}\n```\n\n### Synthesized Output\n\n```swift\nenum EnumTest {\n    private enum Options: String { ... }\n    \n    typealias RawValue = String\n\n    case a, b, c, d, e, f, other(String)\n\n    var rawValue: RawValue {\n        switch self {\n        case .a:\n            return Options.a.rawValue\n        case .b:\n            return Options.b.rawValue\n        case .c:\n            return Options.c.rawValue\n        case .d:\n            return Options.d.rawValue\n        case .e:\n            return Options.e.rawValue\n        case .f:\n            return Options.f.rawValue\n        case .other(let string):\n            return string\n        }\n    }\n\n    init(rawValue: RawValue) {\n        if let this = Options(rawValue: rawValue) {\n            switch this {\n            case .a:\n                self = .a\n            case .b:\n                self = .b\n            case .c:\n                self = .c\n            case .d:\n                self = .d\n            case .e:\n                self = .e\n            case .f:\n                self = .f\n            }\n        } else {\n            self = .other(rawValue)\n        }\n    }\n}\n```\n\n## Supported Protocols\n\nThe following protocols can be explicitly added to the primary enum, and `@OrOther` its conformance will be automatically synthesized:\n- `Equatable`\n- `Hashable`\n- `Encodable` / `Decodable` / `Codable`\n- `CaseIterable`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fedonv%2Forother","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fedonv%2Forother","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fedonv%2Forother/lists"}