{"id":3008,"url":"https://github.com/devxoul/Then","last_synced_at":"2025-08-06T16:32:18.051Z","repository":{"id":39169977,"uuid":"48533709","full_name":"devxoul/Then","owner":"devxoul","description":"✨ Super sweet syntactic sugar for Swift initializers","archived":false,"fork":false,"pushed_at":"2024-03-15T01:42:13.000Z","size":92,"stargazers_count":4217,"open_issues_count":13,"forks_count":292,"subscribers_count":52,"default_branch":"master","last_synced_at":"2024-12-04T14:03:41.412Z","etag":null,"topics":["swift","syntactic-sugar"],"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/devxoul.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":"2015-12-24T08:29:37.000Z","updated_at":"2024-11-30T07:18:23.000Z","dependencies_parsed_at":"2024-06-18T10:57:36.575Z","dependency_job_id":null,"html_url":"https://github.com/devxoul/Then","commit_stats":{"total_commits":124,"total_committers":20,"mean_commits":6.2,"dds":0.2338709677419355,"last_synced_commit":"d41ef523faef0f911369f79c0b96815d9dbb6d7a"},"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devxoul%2FThen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devxoul%2FThen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devxoul%2FThen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devxoul%2FThen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/devxoul","download_url":"https://codeload.github.com/devxoul/Then/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228923759,"owners_count":17992574,"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":["swift","syntactic-sugar"],"created_at":"2024-01-05T20:16:28.810Z","updated_at":"2024-12-09T16:31:20.394Z","avatar_url":"https://github.com/devxoul.png","language":"Swift","funding_links":[],"categories":["Utility","Libs","Swift","2、技术示范","Utilities and Extensions","Utility [🔝](#readme)"],"sub_categories":["Web View","Utility","Other free courses","2.6 环境和开发框架"],"readme":"# Then\n\n![Swift](https://img.shields.io/badge/Swift-5.0-orange.svg)\n[![CocoaPods](http://img.shields.io/cocoapods/v/Then.svg)](https://cocoapods.org/pods/Then)\n[![Build Status](https://travis-ci.org/devxoul/Then.svg?branch=master)](https://travis-ci.org/devxoul/Then)\n\n✨ Super sweet syntactic sugar for Swift initializers.\n\n## At a Glance\n\nInitialize UILabel **then** set its properties.\n\n```swift\nlet label = UILabel().then {\n  $0.textAlignment = .center\n  $0.textColor = .black\n  $0.text = \"Hello, World!\"\n}\n```\n\nThis is equivalent to:\n\n```swift\nlet label: UILabel = {\n  let label = UILabel()\n  label.textAlignment = .center\n  label.textColor = .black\n  label.text = \"Hello, World!\"\n  return label\n}()\n```\n\n## Tips and Tricks\n\n- You can use `then()` to all of `NSObject` subclasses.\n\n    ```swift\n    let queue = OperationQueue().then {\n      $0.maxConcurrentOperationCount = 1\n    }\n    ```\n\n- Want to use with your own types? Just make extensions.\n\n    ```swift\n    extension MyType: Then {}\n    \n    let instance = MyType().then {\n      $0.really = \"awesome!\"\n    }\n    ```\n\n- Use `with()` when copying the value types.\n\n    ```swift\n    let newFrame = oldFrame.with {\n      $0.size.width = 200\n      $0.size.height = 100\n    }\n    newFrame.width // 200\n    newFrame.height // 100\n    ```\n\n- Use `do()` to do something with less typing.\n\n    ```swift\n    UserDefaults.standard.do {\n      $0.set(\"devxoul\", forKey: \"username\")\n      $0.set(\"devxoul@gmail.com\", forKey: \"email\")\n      $0.synchronize()\n    }\n    ```\n\n## Real World Example\n\nHere's an example usage in an UIViewController subclass.\n\n```swift\nfinal class MyViewController: UIViewController {\n\n  let titleLabel = UILabel().then {\n    $0.textColor = .black\n    $0.textAlignment = .center\n  }\n\n  let tableView = UITableView().then {\n    $0.backgroundColor = .clear\n    $0.separatorStyle = .none\n    $0.register(MyCell.self, forCellReuseIdentifier: \"myCell\")\n  }\n\n  override func viewDidLoad() {\n    super.viewDidLoad()\n    self.view.addSubview(self.titleLabel)\n    self.view.addSubview(self.tableView)\n  }\n\n}\n```\n\n## Installation\n\n- **Using  [CocoaPods](https://cocoapods.org)**:\n\n    ```ruby\n    pod 'Then'\n    ```\n\n- **Using [Swift Package Manager](https://swift.org/package-manager)**:\n\n    ```swift\n    import PackageDescription\n\n    let package = Package(\n      name: \"MyAwesomeApp\",\n      dependencies: [\n        .Package(url: \"https://github.com/devxoul/Then\", majorVersion: 2),\n      ]\n    )\n    ```\n\n## License\n\n**Then** is under MIT license. See the [LICENSE](LICENSE) file for more info.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevxoul%2FThen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdevxoul%2FThen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevxoul%2FThen/lists"}