{"id":1293,"url":"https://github.com/ashikahmad/SugarAnchor","last_synced_at":"2025-07-30T20:33:09.169Z","repository":{"id":62456288,"uuid":"90756213","full_name":"ashikahmad/SugarAnchor","owner":"ashikahmad","description":"A simpler way to work with NSLayoutAnchor","archived":false,"fork":false,"pushed_at":"2017-06-12T09:31:17.000Z","size":55,"stargazers_count":20,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-11-26T12:35:19.489Z","etag":null,"topics":["anchor","constraints","ios","layout","swift3"],"latest_commit_sha":null,"homepage":null,"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/ashikahmad.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}},"created_at":"2017-05-09T14:37:58.000Z","updated_at":"2023-02-18T22:49:19.000Z","dependencies_parsed_at":"2022-11-02T00:15:17.507Z","dependency_job_id":null,"html_url":"https://github.com/ashikahmad/SugarAnchor","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ashikahmad%2FSugarAnchor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ashikahmad%2FSugarAnchor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ashikahmad%2FSugarAnchor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ashikahmad%2FSugarAnchor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ashikahmad","download_url":"https://codeload.github.com/ashikahmad/SugarAnchor/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228187626,"owners_count":17882336,"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":["anchor","constraints","ios","layout","swift3"],"created_at":"2024-01-05T20:15:43.131Z","updated_at":"2024-12-04T20:31:15.920Z","avatar_url":"https://github.com/ashikahmad.png","language":"Swift","funding_links":[],"categories":["Layout"],"sub_categories":["Other Hardware","Other free courses"],"readme":"# ![Banner](SugarAnchor-Banner.png)\n\n[![CI Status](http://img.shields.io/travis/ashikahmad/SugarAnchor.svg?style=flat)](https://travis-ci.org/ashikahmad/SugarAnchor)\n[![Version](https://img.shields.io/cocoapods/v/SugarAnchor.svg?style=flat)](http://cocoapods.org/pods/SugarAnchor)\n[![License](https://img.shields.io/cocoapods/l/SugarAnchor.svg?style=flat)](http://cocoapods.org/pods/SugarAnchor)\n[![Platform](https://img.shields.io/cocoapods/p/SugarAnchor.svg?style=flat)](http://cocoapods.org/pods/SugarAnchor)\n\nSugarAnchor is syntactic sugar on `NSLayoutAnchor` to help us write more compact, readable and easy layout code. It wraps up all of `NSLayoutXAxisAnchor`, `NSLayoutYAxisAnchor` and `NSLayoutDimension` functionalities under some easy to use operators to reduce verbosity.\n\n## Features\n\n- Simple, concise, native\u003csup\u003e[1]\u003c/sup\u003e. Almost zero learning curve\n- Typesafe, similar to NSLayoutAnchor\n- Unit tested\n- Small codebase (less than 300 LOC)\n\n\u003e [1] Same NSLayoutAnchor/NSLayoutConstraints, just syntactic sugar on it\n\n## Example\n\nTo run the example project, clone the repo, and run `pod install` from the Example directory first.\n\n## Requirements\n\n- [x] Xcode 8.3 or above\n- [x] Swift 3.1\n- [x] iOS 9.0 or above\n\n## Installation\n\nSugarAnchor is available through [CocoaPods](http://cocoapods.org). To install\nit, simply add the following line to your Podfile:\n\n```ruby\npod \"SugarAnchor\"\n```\n\n## Operator Summary\n\nLet's looks at a simple NSLayoutAnchor code:\n```swift\n(redView.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 20)).isActive = true\n```\n\nWith SugarAnchor, it become:\n```swift\nredView.leadingAnchor =*= view.leadingAnchor + 20\n```\n\nThink `*` as **Active constraint** and `~` as **Inactive constraint**. Then with `=*=`, you'll create an active constraint directly or with `=~=` you may create an inactive constraint which you can activate later.\n\n```swift\nview1.leftAnchor =*= view2.leftAnchor + 10\n\n// Or\n\nlet leftConstraint = (view1.leftAnchor =~= view2.leftAnchor + 10)\nleftConstraint.isActive = true\n```\nIn each case, you'll get the constraint to keep or just ignore. For example, for an active one:\n```swift\nself.heightConstraint = (v1.heightAnchor =*= 200)\n// Later somewhere\nself.heightConstraint.constant = 100\n```\n## Operator list\n\n\nOperator | Description | Example\n--- | --- | ---\n\u003ckbd\u003e =*= \u003c/kbd\u003e | Equal\u003cbr\u003e(Active) | ❖ `v1.leadingAnchor =*= v2.leadingAnchor`\u003cbr\u003e❖ `v1.leftAnchor =*= v2.leftAnchor + 20`\u003cbr\u003e❖ `v1.widthAnchor =*= v2.widthAnchor / 2 + 10`\u003cbr\u003e❖ `v1.heightAnchor =*= 200`\n\u003ckbd\u003e \u003c*= \u003c/kbd\u003e | LessThanOrEqual\u003cbr\u003e(Active) | ❖ `v1.bottomAnchor \u003c*= container.bottomAnchor - 8`\n\u003ckbd\u003e \u003e*= \u003c/kbd\u003e | GreaterThanOrEqual\u003cbr\u003e(Active) | ❖ `v2.leadingAnchor \u003e*= v1.trailingAnchor + 5`\n\u003ckbd\u003e =~= \u003c/kbd\u003e | Equal\u003cbr\u003e(Inactive) | ❖ `(v1.widthAnchor =~= 200).isActive = true`\n\u003ckbd\u003e \u003c~= \u003c/kbd\u003e | LessThanOrEqual\u003cbr\u003e(Inactive) | ❖ `(v1.bottomAnchor \u003c~= container.bottomAnchor - 8).isActive = true`\n\u003ckbd\u003e \u003e~= \u003c/kbd\u003e | GreaterThanOrEqual\u003cbr\u003e(Inactive) | ❖ `(v2.leadingAnchor \u003e~= v1.trailingAnchor + 5).isActive = true`\n\n\n\n## Author\n\nashikahmad, ashikcu@gmail.com\n\n## License\n\nSugarAnchor is available under the MIT license. See the LICENSE file for more info.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fashikahmad%2FSugarAnchor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fashikahmad%2FSugarAnchor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fashikahmad%2FSugarAnchor/lists"}