{"id":19188792,"url":"https://github.com/miquido/mqtagged","last_synced_at":"2026-06-19T15:31:16.801Z","repository":{"id":117573588,"uuid":"508663153","full_name":"miquido/MQTagged","owner":"miquido","description":"Type distinction for Swift. The project was made by Miquido: https://www.miquido.com/","archived":false,"fork":false,"pushed_at":"2023-08-04T13:18:32.000Z","size":17,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-23T03:42:22.390Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/miquido.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}},"created_at":"2022-06-29T11:27:51.000Z","updated_at":"2022-06-29T13:25:29.000Z","dependencies_parsed_at":null,"dependency_job_id":"74124526-4768-4a0d-ab0b-31dddb16273a","html_url":"https://github.com/miquido/MQTagged","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/miquido/MQTagged","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/miquido%2FMQTagged","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/miquido%2FMQTagged/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/miquido%2FMQTagged/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/miquido%2FMQTagged/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/miquido","download_url":"https://codeload.github.com/miquido/MQTagged/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/miquido%2FMQTagged/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34538085,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-19T02:00:06.005Z","response_time":61,"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":[],"created_at":"2024-11-09T11:26:03.259Z","updated_at":"2026-06-19T15:31:16.782Z","avatar_url":"https://github.com/miquido.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MQTagged\n\n[![Platforms](https://img.shields.io/badge/platform-iOS%20|%20iPadOS%20|%20macOS-gray.svg?style=flat)]()\n[![Swift Package Manager compatible](https://img.shields.io/badge/Swift%20Package%20Manager-compatible-brightgreen.svg)](https://github.com/apple/swift-package-manager)\n[![SwiftVersion](https://img.shields.io/badge/Swift-5.6-brightgreen.svg)]()\n\nMQTagged provides a `Tagged` structure which helps differentiating between values of the same type.\n\n## Summary\n\nLet's have an example of a function which authorizes a user based on two string parameters:\n\n```swift\nfunc authorize(_ username: String, _ password: String) {\n  ...\n}\n```\n\nIt is possible to call the function with swapped arguments without any compiler warning. Using a `typealias` also does not solves the issue:\n\n```swift\ntypealias Username = String\ntypealias Password = String\n\nfunc authorize(_ username: Username, _ password: Password) {\n  ...\n}\n\nlet username: Username = \"user@name.com\"\nlet password: Password = \"pa55w0rD\"\n\nauthorize(username, password)\nauthorize(password, username) // It's wrong but still compiles.\n```\n\n`typealias` doesn't cause compiler warning or error when type names are not matching since resolved type is the same. MQTagged solution to this problem is to use `Tag` type:\n\n```swift\nenum UsernameTag {}\nenum PasswordTag {}\n\ntypealias Username = Tagged\u003cString, UsernameTag\u003e\ntypealias Password = Tagged\u003cString, PasswordTag\u003e\n\nfunc authorize(_ username: Username, _ password: Password) {\n  ...\n}\n```\n\nNow any call with swapped parameters won't compile.\n\n```swift\nlet username: Username = \"user@name.com\"\nlet password: Password = \"pa55w0rD\"\n\nauthorize(username, password)\nauthorize(password, username) // This won't compile.\n```\n\n## Installation\n`MQTagged` can be integrated through Swift Package Manager. In your `Package.swift` file add the following `dependency`:\n\n```swift\ndependencies: [\n  .package(\n    url: \"https://github.com/miquido/mqtagged.git\",\n    .upToNextMajor(\"0.1.0\")\n  )\n]\n```\n\n## License\n\nCopyright 2022-2023 Miquido\n\nLicensed under the Apache License, Version 2.0 (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at\n\nhttp://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmiquido%2Fmqtagged","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmiquido%2Fmqtagged","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmiquido%2Fmqtagged/lists"}