{"id":30641131,"url":"https://github.com/orchetect/swiftuitokenfield","last_synced_at":"2026-05-03T23:31:46.983Z","repository":{"id":309167123,"uuid":"1035352863","full_name":"orchetect/SwiftUITokenField","owner":"orchetect","description":"Richly-featured SwiftUI wrapper for NSTokenField.","archived":false,"fork":false,"pushed_at":"2026-04-18T23:10:16.000Z","size":123,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-04-19T01:16:46.689Z","etag":null,"topics":["macos","nstokenfield","nstokenfieldcell","swift","swiftui"],"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/orchetect.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"github":"orchetect"}},"created_at":"2025-08-10T07:58:24.000Z","updated_at":"2026-04-18T23:10:20.000Z","dependencies_parsed_at":"2025-09-13T09:07:10.628Z","dependency_job_id":"4625bc06-71f3-4cd3-9a50-b5741e7cef8f","html_url":"https://github.com/orchetect/SwiftUITokenField","commit_stats":null,"previous_names":["orchetect/swiftuitokenfield"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/orchetect/SwiftUITokenField","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orchetect%2FSwiftUITokenField","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orchetect%2FSwiftUITokenField/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orchetect%2FSwiftUITokenField/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orchetect%2FSwiftUITokenField/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/orchetect","download_url":"https://codeload.github.com/orchetect/SwiftUITokenField/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orchetect%2FSwiftUITokenField/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32589019,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-03T22:12:39.696Z","status":"ssl_error","status_checked_at":"2026-05-03T22:09:10.534Z","response_time":103,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["macos","nstokenfield","nstokenfieldcell","swift","swiftui"],"created_at":"2025-08-31T01:39:23.220Z","updated_at":"2026-05-03T23:31:46.978Z","avatar_url":"https://github.com/orchetect.png","language":"Swift","funding_links":["https://github.com/sponsors/orchetect"],"categories":[],"sub_categories":[],"readme":"# SwiftUI TokenField\n\n[![Platforms - macOS](https://img.shields.io/badge/platforms-macOS-blue.svg?style=flat)](https://developer.apple.com/swift) ![Swift 6.0](https://img.shields.io/badge/Swift-6.0-blue.svg?style=flat) [![Xcode 16](https://img.shields.io/badge/Xcode-16-blue.svg?style=flat)](https://developer.apple.com/swift) [![License: MIT](http://img.shields.io/badge/license-MIT-lightgrey.svg?style=flat)](https://github.com/orchetect/SwiftUITokenField/blob/main/LICENSE)\n\nRichly-featured SwiftUI wrapper for `NSTokenField` on macOS.\n\n## Token Field\n\nThe `TokenField` view allows entry of tokens only.\n\nThe user may be allowed to define custom tokens, or tokens may be restricted to a pre-defined set.\n\n![Screenshot](Images/tokenfield-screenshot.png)\n\n- Supports text entry auto-complete for tokens\n- Token substitutions may be shown in place of their raw token identifier if desired\n- Tokens may also be added programmatically from a menu, or using drag \u0026 drop from a list of tokens in the UI\n- Token entry can be restricted to only one use per token, disallowing duplicate usage of tokens\n- Editing can be disabled to allow the field to act as a read-only label\n\n## Token TextField\n\nThe `TokenTextField` view allows mixed entry of tokens and plain text. It uses `TokenizedString` as its data binding type, allowing strong-typing of the senquence.\n\nThis field allows the user to define a token-substitution string template.\n\n![Screenshot](Images/tokentextfield-screenshot.png)\n\n- Supports text entry auto-complete for tokens\n- Token substitutions may be shown in place of their raw token identifier if desired\n- Tokens may also be added programmatically from a menu, or using drag \u0026 drop from a list of tokens in the UI\n- Token entry can be restricted to only one use per token, disallowing duplicate usage of tokens\n- Editing can be disabled to allow the field to act as a read-only label\n- Methods for encoding/decoding tokenized strings\n\n## Sample Usage\n\nThe fields work best when you define a token enum that is `String` `RawRepresentable` and conforms to `CaseIterable`. This allows the field to automatically synthesize token encoding/decoding and text auto-complete entries.\n\n```swift\nimport SwiftUI\nimport SwiftUITokenField\n\nenum MyToken: String, CaseIterable {\n    case name\n    case date\n    case time\n}\n\nstruct ContentView: View {\n    @State private var tokenizedString = TokenizedString\u003cMyToken\u003e()\n    \n    var body: some View {\n        TokenTextField($tokenizedString)\n    }\n}\n```\n\nToken substitution:\n\n```swift\nlet tokenizedString = TokenizedString\u003cMyToken\u003e([\n    .string(\"The date is \"),\n    .token(.date),\n    .string(\", and the time is \"),\n    .token(.time),\n    .string(\".\")\n])\n\nlet substitutedString = tokenizedString.string { token in\n    switch token {\n        case .name: \"John Doe\"\n        case .date: Date().formatted(date: .abbreviated, time: .omitted)\n        case .time: Date().formatted(date: .omitted, time: .standard)\n    }  \n}\nprint(substitutedString)\n// \"The date is Friday, August 8, 2025, and the time is 1:05:18 PM.\"\n```\n\nTokenized string serialization:\n\nBy default `%[` and `]` token prefix/suffix is used, but custom ones can be supplied to the method.\n\n```swift\nlet encoded = tokenizedString.tokenizedString()\nprint(encoded)\n// \"The date is %[date], and the time is %[time].\"\n\nlet decoded = try TokenizedString\u003cMyToken\u003e(from: \"The date is %[date], and the time is %[time].\")\n```\n\n### Advanced Usage\n\nThe fields support `NSTokenField` text entry auto-completion.\n\nFor token types that:\n\n- conform to `RawRepresentable` with `String` raw value type\n- conform to `CaseIterable`\n\nthese auto-completions are synthesized automatically. Encoding and decoding tokens is also synthesized.\n\n```swift\nenum MyToken: String, CaseIterable {\n    case name\n    case date\n    case time\n}\n\nstruct ContentView: View {\n    @State private var tokenizedString = TokenizedString\u003cMyToken\u003e()\n    \n    var body: some View {\n        TokenTextField($tokenizedString)\n    }\n}\n```\n\nFor token types that do not conform to `RawRepresentable`, completions may be supplied manually by providing a dictionary keyed by token where its value corresponds to its auto-complete text. Since the token does not conform to `RawRepresentable`, its encoding and decoding must be specified.\n\n```swift\nenum MyToken {\n    case name\n    case date\n    case time\n    \n    init?(rawValue: String) { /* ... */ }\n    var rawValue: String { /* ... */  }\n}\n\nstruct ContentView: View {\n    @State private var tokenizedString = TokenizedString\u003cMyToken\u003e()\n    \n    var body: some View {\n        TokenTextField(\n            $tokenizedString,\n            completions: [.name: \"name\", .date: \"date\", .time: \"time\"],\n            decode: { token in token.rawValue },\n            encode: { string in Token(rawValue: string) }\n        )\n    }\n}\n```\n\n## Installation\n\n### Swift Package Manager (SPM)\n\nAdd this package to your Xcode project or Swift package using `https://github.com/orchetect/SwiftUITokenField` as the URL.\n\n## Documentation / Examples\n\nThere is no formal documentation at this time, but most types and methods in the package have inline documentation to help explain their purpose.\n\nSee the [Examples](Examples) folder for a quick way to get started.\n\n## Author\n\nCoded by a bunch of 🐹 hamsters in a trenchcoat that calls itself [@orchetect](https://github.com/orchetect).\n\n## License\n\nLicensed under the MIT license. See [LICENSE](https://github.com/orchetect/SwiftUITokenField/blob/master/LICENSE) for details.\n\n## Sponsoring\n\nIf you enjoy using SwiftUITokenField and want to contribute to open-source financially, GitHub sponsorship is much appreciated. Feedback and code contributions are also welcome.\n\n## Community \u0026 Support\n\nPlease do not email maintainers for technical support. Several options are available for issues and questions:\n\n- Questions and feature ideas can be posted to [Discussions](https://github.com/orchetect/SwiftUITokenField/discussions).\n- If an issue is a verifiable bug with reproducible steps it may be posted in [Issues](https://github.com/orchetect/SwiftUITokenField/issues).\n\n## Contributions\n\nContributions are welcome. Posting in [Discussions](https://github.com/orchetect/SwiftUITokenField/discussions) first prior to new submitting PRs for features or modifications is encouraged.\n\n## Code Quality \u0026 AI Contribution Policy\n\nIn an effort to maintain a consistent level of code quality and safety, this repository was built by hand and is maintained without the use of AI code generation.\n\nAI-assisted contributions are welcome, but must remain modest in scope, maintain the same degree of quality and care, and be thoroughly vetted before acceptance.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Forchetect%2Fswiftuitokenfield","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Forchetect%2Fswiftuitokenfield","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Forchetect%2Fswiftuitokenfield/lists"}