{"id":19809497,"url":"https://github.com/space-code/builder-macro","last_synced_at":"2025-02-28T12:45:07.018Z","repository":{"id":258923431,"uuid":"815474804","full_name":"space-code/builder-macro","owner":"space-code","description":"builder-macro is a macro that implements the Builder design pattern in Swift","archived":false,"fork":false,"pushed_at":"2024-10-23T06:58:32.000Z","size":319,"stargazers_count":0,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"dev","last_synced_at":"2024-10-24T20:41:24.767Z","etag":null,"topics":["builder","builder-design-pattern","builder-pattern","ios","macos","macros","swift-macro","swift-macros","tvos"],"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/space-code.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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":"2024-06-15T09:12:28.000Z","updated_at":"2024-10-23T06:05:48.000Z","dependencies_parsed_at":"2024-11-12T09:17:14.227Z","dependency_job_id":"6b12a12e-2e70-4e9f-8ad6-4a53c9ff7434","html_url":"https://github.com/space-code/builder-macro","commit_stats":null,"previous_names":["space-code/builder-macro"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/space-code%2Fbuilder-macro","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/space-code%2Fbuilder-macro/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/space-code%2Fbuilder-macro/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/space-code%2Fbuilder-macro/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/space-code","download_url":"https://codeload.github.com/space-code/builder-macro/tar.gz/refs/heads/dev","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241152745,"owners_count":19918674,"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":["builder","builder-design-pattern","builder-pattern","ios","macos","macros","swift-macro","swift-macros","tvos"],"created_at":"2024-11-12T09:17:11.997Z","updated_at":"2025-02-28T12:45:06.977Z","avatar_url":"https://github.com/space-code.png","language":"Swift","readme":"![BuilderMacro is a macro that implements the Builder design pattern in Swift](https://raw.githubusercontent.com/space-code/builder-macro/dev/Resources/builder-macro.png)\n\n\u003ch1 align=\"center\" style=\"margin-top: 0px;\"\u003ebuilder-macro\u003c/h1\u003e\n\n\u003cp align=\"center\"\u003e\n\u003ca href=\"https://github.com/space-code/builder-macro/blob/main/LICENSE\"\u003e\u003cimg alt=\"License\" src=\"https://img.shields.io/github/license/space-code/builder-macro?style=flat\"\u003e\u003c/a\u003e \n\u003ca href=\"https://swiftpackageindex.com/space-code/builder-macro\"\u003e\u003cimg alt=\"Swift Compatibility\" src=\"https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fspace-code%2Fbuilder-macro%2Fbadge%3Ftype%3Dswift-versions\"/\u003e\u003c/a\u003e \n\u003ca href=\"https://swiftpackageindex.com/space-code/builder-macro\"\u003e\u003cimg alt=\"Platform Compatibility\" src=\"https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fspace-code%2Fbuilder-macro%2Fbadge%3Ftype%3Dplatforms\"/\u003e\u003c/a\u003e \n\u003ca href=\"https://codecov.io/gh/space-code/builder-macro\"\u003e\u003cimg alt=\"CodeCov\" src=\"https://codecov.io/gh/space-code/builder-macro/graph/badge.svg?token=0N0jMJnozP\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/space-code/builder-macro\"\u003e\u003cimg alt=\"CI\" src=\"https://github.com/space-code/builder-macro/actions/workflows/ci.yml/badge.svg?branch=main\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/space-code/builder-macro\"\u003e\u003cimg alt=\"GitHub release; latest by date\" src=\"https://img.shields.io/github/v/release/space-code/builder-macro\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/apple/swift-package-manager\" alt=\"builder-macro on Swift Package Manager\" title=\"builder-macro on Swift Package Manager\"\u003e\u003cimg src=\"https://img.shields.io/badge/Swift%20Package%20Manager-compatible-brightgreen.svg\" /\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n## Description\n`builder-macro` is a macro that implements the Builder design pattern in Swift.\n\n- [Usage](#usage)\n- [Requirements](#requirements)\n- [Installation](#installation)\n- [Communication](#communication)\n- [Contributing](#contributing)\n- [Author](#author)\n- [License](#license)\n\n## Usage\n```swift\nimport BuilderMacro\n\n@Builder\nstruct Person {\n    let id: UUID\n    let name: String\n    let bday: Date\n}\n\n// Expanded\n\nstruct Person {\n    let firstName: String, let lastName: String, let middleName: String\n    let birthday: Date\n    let city: String\n\n    struct PersonBuilder {\n        var firstName: String?\n        var lastName: String?\n        var middleName: String?\n        var birthday: Date?\n        var city: String?\n\n        func firstName(_ firstName: String) -\u003e Self {\n            var copy = self\n            copy.firstName = firstName\n            return copy\n        }\n\n        func lastName(_ lastName: String) -\u003e Self {\n            var copy = self\n            copy.lastName = lastName\n            return copy\n        }\n\n        func middleName(_ middleName: String) -\u003e Self {\n            var copy = self\n            copy.middleName = middleName\n            return copy\n        }\n\n        func birthday(_ birthday: Date) -\u003e Self {\n            var copy = self\n            copy.birthday = birthday\n            return copy\n        }\n\n        func city(_ city: String) -\u003e Self {\n            var copy = self\n            copy.city = city\n            return copy\n        }\n\n        enum BuildError: Swift.Error {\n            case missingRequiredField(description: String)\n        }\n\n        func build() throws -\u003e Person {\n            guard let firstName = firstName else {\n                throw BuildError.missingRequiredField(description: \"firstName\")\n            }\n\n            guard let lastName = lastName else {\n                throw BuildError.missingRequiredField(description: \"lastName\")\n            }\n\n            guard let middleName = middleName else {\n                throw BuildError.missingRequiredField(description: \"middleName\")\n            }\n\n            guard let birthday = birthday else {\n                throw BuildError.missingRequiredField(description: \"birthday\")\n            }\n\n            guard let city = city else {\n                throw BuildError.missingRequiredField(description: \"city\")\n            }\n\n            return Person(\n                firstName: firstName,\n                lastName: lastName,\n                middleName: middleName,\n                birthday: birthday,\n                city: city\n            )\n        }\n    }\n}\n```\n\nIf a property type is optional, you can force validation of nil values by passing the addGuards parameter to the builder macro like this::\n\n```swift\nimport BuilderMacro\n\n@Builder(addGuards: true)\nstruct Person {\n    let id: UUID\n    let name: String\n    let bday: Date\n}\n```\n\n## Requirements\n- iOS 13.0+ / macOS 10.15+ / tvOS 13.0+ / watchOS 6.0+\n- Xcode 15.0\n- Swift 5.9\n\n## Installation\n### Swift Package Manager\n\nThe [Swift Package Manager](https://swift.org/package-manager/) is a tool for automating the distribution of Swift code and is integrated into the `swift` compiler. It is in early development, but `builder-macro` does support its use on supported platforms.\n\nOnce you have your Swift package set up, adding `builder-macro` as a dependency is as easy as adding it to the `dependencies` value of your `Package.swift`.\n\n```swift\ndependencies: [\n    .package(url: \"https://github.com/space-code/builder-macro.git\", .upToNextMajor(from: \"1.0.0\"))\n]\n```\n\n## Communication\n- If you **found a bug**, open an issue.\n- If you **have a feature request**, open an issue.\n- If you **want to contribute**, submit a pull request.\n\n## Contributing\nBootstrapping development environment\n\n```\nmake bootstrap\n```\n\nPlease feel free to help out with this project! If you see something that could be made better or want a new feature, open up an issue or send a Pull Request!\n\n## Author\nNikita Vasilev, nv3212@gmail.com\n\n## License\nbuilder-macro is available under the MIT license. See the LICENSE file for more info.","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspace-code%2Fbuilder-macro","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fspace-code%2Fbuilder-macro","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspace-code%2Fbuilder-macro/lists"}