{"id":16322246,"url":"https://github.com/p-x9/aliasmacro","last_synced_at":"2025-03-16T14:31:01.570Z","repository":{"id":175923769,"uuid":"654728228","full_name":"p-x9/AliasMacro","owner":"p-x9","description":"🎭 A Swift macros for defining aliases for types, functions, variables, etc.","archived":false,"fork":false,"pushed_at":"2024-05-06T02:22:46.000Z","size":85,"stargazers_count":32,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-16T03:04:03.910Z","etag":null,"topics":["macro","spm","swiftmacros","swiftpackage","swiftpackagemanager"],"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/p-x9.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":"2023-06-16T19:57:55.000Z","updated_at":"2025-02-28T00:59:23.000Z","dependencies_parsed_at":"2024-01-15T10:13:12.669Z","dependency_job_id":"2c39df15-f21a-4f98-8c0e-03b4361f20b4","html_url":"https://github.com/p-x9/AliasMacro","commit_stats":null,"previous_names":["p-x9/aliasmacro"],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/p-x9%2FAliasMacro","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/p-x9%2FAliasMacro/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/p-x9%2FAliasMacro/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/p-x9%2FAliasMacro/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/p-x9","download_url":"https://codeload.github.com/p-x9/AliasMacro/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243882398,"owners_count":20363126,"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":["macro","spm","swiftmacros","swiftpackage","swiftpackagemanager"],"created_at":"2024-10-10T22:50:22.873Z","updated_at":"2025-03-16T14:31:01.243Z","avatar_url":"https://github.com/p-x9.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# AliasMacro\n\nSwift Macro for defining aliases for types, functions, or variables.\n\n\u003c!-- # Badges --\u003e\n\n[![Github issues](https://img.shields.io/github/issues/p-x9/AliasMacro)](https://github.com/p-x9/AliasMacro/issues)\n[![Github forks](https://img.shields.io/github/forks/p-x9/AliasMacro)](https://github.com/p-x9/AliasMacro/network/members)\n[![Github stars](https://img.shields.io/github/stars/p-x9/AliasMacro)](https://github.com/p-x9/AliasMacro/stargazers)\n[![Github top language](https://img.shields.io/github/languages/top/p-x9/AliasMacro)](https://github.com/p-x9/AliasMacro/)\n\n## Usage\n\nA macro that can be attached to a type, function or variable.\n\n### Variable\n\nYou can define an alias for a variable as follows\n\n```swift\nclass SomeClass {\n    @Alias(\"title\")\n    var text: String = \"hello\"\n}\n\n/* ↓↓↓↓↓ */\n\nlet someClass = SomeClass()\n\nprint(text) // =\u003e \"hello\"\nprint(title) // =\u003e \"hello\"\n```\n\n### Function/Method\n\nYou can define an alias for a function as follows.\nIn this way, you can call both `hello(\"aaa\", at: Date())` and `こんにちは(\"aaa\", at: Date())`.\n\n```swift\nclass SomeClass {\n    @Alias(\"こんにちは\")\n    func hello(_ text: String, at date: Date) {\n        /* --- */\n        print(text)\n    }\n}\n\n/* ↓↓↓↓↓ */\n\nlet someClass = SomeClass()\n\nsomeClass.hello(\"aaa\", at: Date()) // =\u003e \"aaa\"\nsomeClass.こんにちは(\"aaa\", at: Date()) // =\u003e \"aaa\"\n```\n\n#### Customize Argument Label\n\nArgument labels can also be customized by separating them with \":\".\n\n```swift\nclass SomeClass {\n    @Alias(\"こんにちは::いつ\")\n    func hello(_ text: String, at date: Date) {\n        /* --- */\n        print(text)\n    }\n\n    @Alias(\"こんにちは2:_:_\") // Omit argument labels\n    func hello2(_ text: String, at date: Date) {\n        /* --- */\n        print(text)\n    }\n\n    @Alias(\"こんにちは3::宛\") // The first argument label is inherited. The second is customized\n    func hello3(_ text: String, at date: Date, to: String) {\n        /* --- */\n        print(text)\n    }\n}\n\n/* ↓↓↓↓↓ */\n\nlet someClass = SomeClass()\n\nsomeClass.hello(\"aaa\", at: Date()) // =\u003e \"aaa\"\nsomeClass.こんにちは(\"aaa\", いつ: Date()) // =\u003e \"aaa\"\n\nsomeClass.hello2(\"aaa\", at: Date()) // =\u003e \"aaa\"\nsomeClass.こんにちは2(\"aaa\", Date()) // =\u003e \"aaa\"\n\nsomeClass.hello3(\"aaa\", at: Date(), to: \"you\") // =\u003e \"aaa\"\nsomeClass.こんにちは3(\"aaa\", at: Date(), 宛: \"あなた\") // =\u003e \"aaa\"\n```\n\n### Enum Case\n\nYou can define alias for enum case.\n\nFor example, suppose we define the following.\n\n```swift\nenum Difficulty {\n    @Alias(\"beginner\")\n    case easy\n\n    @Alias(\"normal\")\n    case medium\n\n    @Alias(\"challenge\")\n    case hard\n\n    @Alias(\"extreme\")\n    case expert\n\n    @Alias(\"ultimate\")\n    case master(level: Int)\n}\n```\n\nAt this time, the macro is expanded as follows.\n\n```swift\nenum Difficulty {\n    case easy\n    case medium\n    case hard\n    case expert\n    case master(level: Int)\n\n    static let beginner: Self = .easy\n    static let normal: Self = .medium\n    static let challenge: Self = .hard\n    static let extreme: Self = .expert\n\n    static func ultimate(level: Int) -\u003e Self {\n        .master(level)\n    }\n}\n```\n\n### associatedtype\n\n```swift\nprotocol APIRequest {\n    @Alias(\"Reply\")\n    associatedtype Response\n}\n```\n\n↓↓↓\n\n```swift\nprotocol APIRequest {\n    associatedtype Response\n\n    typealias Reply = Response\n}\n```\n\n### Class/Struct/Enum/Actor\n\nFor example, the `ViewController` can also be referenced as a `VC` by writing the following.\n(If this macro is used for type, it is defined internally simply using `typealias`.)\n\n\u003e **Warning**\n\u003e `PeerMacro` with arbitrary specified in `names` cannot be used in global scope.\n\u003e [Restrictions on arbitrary names](https://github.com/apple/swift-evolution/blob/main/proposals/0389-attached-macros.md#restrictions-on-arbitrary-names)\n\n```swift\n@Alias(\"VC\")\nclass ViewContoroller: UIViewController {\n    /* --- */\n}\n\n/* ↓↓↓↓↓ */\n\nprint(ViewContoroller.self) // =\u003e \"ViewController\"\nprint(VC.self) // =\u003e \"ViewController\"\n```\n\n### Multiple Aliases\n\nMultiple aliases can be defined by adding multiple macros as follows\n\n```swift\n@Alias(\"hello\")\n@Alias(\"こんにちは\")\nvar text: String = \"Hello\"\n```\n\n### Specify Access Modifier of Alias\n\nYou can specify an alias access modifier as follows.\n\n```swift\n@Alias(\"hello\", access: .public)\nprivate var text: String = \"Hello\"\n```\n\nIf set \"inherit\", it will inherit from the original definition.\n\n```swift\n@Alias(\"hello\", access: .inherit)\nprivate var text: String = \"Hello\"\n```\n\n## License\n\nAliasMacro is released under the MIT License. See [LICENSE](./LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fp-x9%2Faliasmacro","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fp-x9%2Faliasmacro","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fp-x9%2Faliasmacro/lists"}