{"id":19031095,"url":"https://github.com/alexito4/swiftusing","last_synced_at":"2025-04-23T16:28:06.738Z","repository":{"id":147635498,"uuid":"182682132","full_name":"alexito4/SwiftUsing","owner":"alexito4","description":"Implementation of the `using` feature in Swift by code generation with SwiftSyntax","archived":false,"fork":false,"pushed_at":"2019-04-22T14:46:50.000Z","size":12,"stargazers_count":9,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-04-18T01:47:56.458Z","etag":null,"topics":["code-generation","jai","swift","swiftsyntax","using"],"latest_commit_sha":null,"homepage":"https://alejandromp.com/blog/2019/04/22/implementing-using-in-swift-with-swiftsyntax/","language":"Swift","has_issues":false,"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/alexito4.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":"2019-04-22T08:51:39.000Z","updated_at":"2023-06-28T09:10:48.000Z","dependencies_parsed_at":null,"dependency_job_id":"c60a9e4e-2721-4da0-b968-bdd62d387279","html_url":"https://github.com/alexito4/SwiftUsing","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexito4%2FSwiftUsing","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexito4%2FSwiftUsing/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexito4%2FSwiftUsing/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexito4%2FSwiftUsing/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alexito4","download_url":"https://codeload.github.com/alexito4/SwiftUsing/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250470482,"owners_count":21435811,"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":["code-generation","jai","swift","swiftsyntax","using"],"created_at":"2024-11-08T21:21:24.562Z","updated_at":"2025-04-23T16:28:06.711Z","avatar_url":"https://github.com/alexito4.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"**SwiftUsing** brings to Swift the `using` feature from Jai, [Jonathan Blow](https://twitter.com/Jonathan_Blow)'s programming language. It uses [SwiftSyntax](https://github.com/apple/swift-syntax) to code generate the required code.\n\nTo learn more about **SwiftUsing** development you can check out the blog post [Implementing using in Swift with SwiftSyntax](http://alejandromp.com/blog/2019/04/22/implementing-using-in-swift-with-swiftsyntax/).\n\n## What is `using`\n\n`using` helps with [Struct composition](https://alejandromp.com/blog/2018/02/03/using-structs-swift-jai-oop/).\n\nIt allows you to recover the nice syntax from class inheritance when you use `struct`s instead.\n\n```swift\nstruct User {\n    var name: String\n    var age: Int\n}\n\nstruct Friend {\n    // using\n    let user: User\n    var friendshipDate: Date\n}\n\nfriend.name // with class inheritance\nfriend.user.name // with struct composition :(\nfriend.name // with struct composition and using !!\n```\n\n## Usage\n\n1. Annotate a property with a comment: `// using`\n\n```swift\nstruct Friend {\n    ...\n    // using          \u003c- add this comment\n    let user: User\n    ...\n}\n```\n\n*Note that both types must be in the same file. See Known limitations below.*\n\n2. Run the command line tool\n\n⚠️ This command will overwrite the original file so make sure you have a copy or you're using a versioning control system like Git in case something goes wrong.\n\n```swift\nswiftusing /path/to/file\n```\n\n## Installation\n\nClone the repo and run `make install`.\n\n## Known limitations\n\n- Basic declaration syntax `let/var identifier: Type`\n- Reliant on comments (is just an external tool after all)\n- Single file, using types must be in the same file.\n- No collision detection, the compiler will error instead.\n\n## Acknowledgements\n\n- [Jonathan Blow](https://twitter.com/Jonathan_Blow) for sharing the development of Jai\n- [pointfree](https://www.pointfree.co/episodes/ep53-swift-syntax-enum-properties) for the informative and inspiring videos\n- [Swift AST Explorer](https://swift-ast-explorer.kishikawakatsumi.com)\n- [swift-syntax](https://github.com/apple/swift-syntax) obviously!\n- [Yaap](https://github.com/hartbit/Yaap)\n- [PackageBuilder](https://github.com/pixyzehn/PackageBuilder)\n\n## Contributions \u0026 support\n\n**SwiftUsing** is developed completely in the open, and your contributions are more than welcome.\n\nThis project does not come with GitHub Issues-based support, and users are instead encouraged to become active participants in its continued development — by fixing any bugs that they encounter, or improving the documentation wherever it’s found to be lacking.\n\nIf you wish to make a change, [open a Pull Request](https://github.com/alexito4/SwiftUsing/pull/new) — even if it just contains a draft of the changes you’re planning, or a test that reproduces an issue — and we can discuss it further from there.\n\n## Author\n\nAlejandro Martinez | http://alejandromp.com | [@alexito4](https://twitter.com/alexito4)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexito4%2Fswiftusing","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falexito4%2Fswiftusing","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexito4%2Fswiftusing/lists"}