{"id":18131523,"url":"https://github.com/chenhaiteng/gradientbuilder","last_synced_at":"2026-05-17T19:06:01.830Z","repository":{"id":143183770,"uuid":"395683976","full_name":"chenhaiteng/GradientBuilder","owner":"chenhaiteng","description":"A custom result builder to help build gradient easily.","archived":false,"fork":false,"pushed_at":"2024-10-04T07:32:24.000Z","size":36,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-14T09:47:40.387Z","etag":null,"topics":["color","gradient-color","resultbuilder","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/chenhaiteng.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":"2021-08-13T14:27:57.000Z","updated_at":"2024-01-25T08:38:15.000Z","dependencies_parsed_at":"2025-02-12T21:30:42.574Z","dependency_job_id":"e3956581-bbd5-4707-99bb-8e0005ce8db4","html_url":"https://github.com/chenhaiteng/GradientBuilder","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chenhaiteng%2FGradientBuilder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chenhaiteng%2FGradientBuilder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chenhaiteng%2FGradientBuilder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chenhaiteng%2FGradientBuilder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chenhaiteng","download_url":"https://codeload.github.com/chenhaiteng/GradientBuilder/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247502645,"owners_count":20949303,"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":["color","gradient-color","resultbuilder","swift","swiftui"],"created_at":"2024-11-01T12:07:50.274Z","updated_at":"2026-05-17T19:05:56.807Z","avatar_url":"https://github.com/chenhaiteng.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# GradientBuilder\n\nFor design detail, read [Go through swift result builders](https://chenhaiteng.github.io/swift/2021/08/16/go-through-swift-result-builders.html)\n\n## Installation:\n\n### CocoaPods\nGradientBuilder is now available through [CocoaPods](https://cocoapods.org). To install\nit, simply add the following line to your Podfile:\n\n```ruby\npod 'GradientBuilder'\n```\n\n### Swift Package Manager\nGradientBuilder is published with Swift Package Manager, you can get more information at ![Swift Package Manager(GitHub)](https://github.com/apple/swift-package-manager), ![Package Manager(swift.org)](https://swift.org/package-manager/), and ![Swift Packages(Apple)](https://developer.apple.com/documentation/swift_packages)\n\n#### - Add to Xcode(To use this package in your application):\n\n1. File \u003e Swift Packages \u003e Add Package Dependency...\n2. Choose Project you want to add GradientBuilder\n3. Paste repository https://github.com/chenhaiteng/GradientBuilder.git\n4. Rules \u003e Version: Up to Next Major 1.0.0\nIt's can also apply Rules \u003e Branch : main to access the latest code.\n\n**Note:** It might need to link GradientBuilder to your target maunally.\n1. Open *Project Editor* by tap on root of project navigator\n2. Choose the target you want to use GradientBuilder.\n3. Choose **Build Phases**, and expand **Link Binary With Libraries**\n4. Tap on **+** button, and choose GradientBuilder to add it.\n\n#### - Add to SPM package(To use this package in your library/framework):\n```swift\ndependencies: [\n    .package(name: \"GradientBuilder\", url: \" https://github.com/chenhaiteng/GradientBuilder.git\", from: \"1.0.0\")\n    // To specify branch, use following statement to instead of.\n    // .package(name: \"GradientBuilder\", url: \" https://github.com/chenhaiteng/GradientBuilder.git\", .branch(\"branch_name\"))\n],\ntargets: [\n    .target(\n        name: \"MyPackage\",\n        dependencies: [\"GradientBuilder\"]),\n]\n```\n---\n## How to use\n\n1. apply on function\n```swift\n// Create a Gradient, then inject it into specified gradient shape.\n@GradientBuilder\nfunc builder() -\u003e Gradient {\n    Color.red\n    Color.blue\n    Color.yellow\n}\n\nlet g = builder()\nlet angularGradient = AngularGradient(gradient: g, center: .center)\n\n// Or create gradient shape directly\n@GradientBuilder\nfunc angularBuilder() -\u003e AngularGradient {\n    Color.red\n    Color.blue\n    Color.yellow\n}\n\nlet angular = angularBuilder()\n```\n\n2. apply on a arameter in a function declaration\n```swift\nfunc createGradient(@GradientBuilder builder: ()-\u003eGradient) -\u003e Gradient {\n    return builder()\n}\n\nlet g = createGradient {\n    Color.red\n    Color.blue\n    Color.yellow\n}\n```\n\n3. apply on a variable or subscript\n```swift\nenum GrayGradient {\n    @GradientBuilder static subscript(_ degree: Int) -\u003e LinearGradient {\n        if degree \u003e 0 {\n            for i in 0..\u003cdegree {\n                Color.white.opacity(Double(i)/Double(degree))\n            }\n        } else {\n            Color.white\n        }\n    }\n}\n\nlet gray_g = GrayGradient[3]\n```\n\n4. Support different input types\n```swift\nlet g = createGradient {\n    (1.0, 1.0, 1.0, 0.5) //RGBA with float, value from 0.0 to 1.0\n    (255, 255, 255, 210) //RGBA8888 format, vlaue from 0 to 255\n    Color.white // Color \n}\n\nlet g_stop = createGradient {\n    Gradient.Stop(color: .red, location: 0.2)\n    (Color.blue, 0.5)\n    (.green, 0.7)\n}\n```\n\nNote that it's **NOT** allow to mix Color with Stop:\n```swift\nlet g = createGradient {\n    (1.0, 1.0, 1.0, 0.5) //RGBA with float, value from 0.0 to 1.0\n    (255, 255, 255, 210) //RGBA8888 format, vlaue from 0 to 255\n    (.green, 0.7) // Invalid!!! show ambiguous error!!!!\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchenhaiteng%2Fgradientbuilder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchenhaiteng%2Fgradientbuilder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchenhaiteng%2Fgradientbuilder/lists"}