{"id":26281056,"url":"https://github.com/yonat/sweeterswift","last_synced_at":"2025-05-07T05:10:56.003Z","repository":{"id":38455088,"uuid":"196721946","full_name":"yonat/SweeterSwift","owner":"yonat","description":"Extensions and syntactic sugar to enrich the Swift standard library, iOS frameworks, and SwifterSwift.","archived":false,"fork":false,"pushed_at":"2024-11-01T13:50:17.000Z","size":90,"stargazers_count":11,"open_issues_count":1,"forks_count":14,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-01T08:36:16.152Z","etag":null,"topics":["cocoapods","ios","swift","swift-extensions","swift-library","swifterswift","syntactic-sugar","uikit"],"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/yonat.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.txt","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},"funding":{"github":["yonat"]}},"created_at":"2019-07-13T12:58:56.000Z","updated_at":"2024-11-01T13:50:21.000Z","dependencies_parsed_at":"2024-06-19T23:07:26.396Z","dependency_job_id":null,"html_url":"https://github.com/yonat/SweeterSwift","commit_stats":{"total_commits":49,"total_committers":2,"mean_commits":24.5,"dds":"0.020408163265306145","last_synced_commit":"d324c3ce0d021f8d1f11f10014ad597fad60e36c"},"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yonat%2FSweeterSwift","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yonat%2FSweeterSwift/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yonat%2FSweeterSwift/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yonat%2FSweeterSwift/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yonat","download_url":"https://codeload.github.com/yonat/SweeterSwift/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252817636,"owners_count":21808706,"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":["cocoapods","ios","swift","swift-extensions","swift-library","swifterswift","syntactic-sugar","uikit"],"created_at":"2025-03-14T15:18:59.360Z","updated_at":"2025-05-07T05:10:55.982Z","avatar_url":"https://github.com/yonat.png","language":"Swift","funding_links":["https://github.com/sponsors/yonat"],"categories":[],"sub_categories":[],"readme":"# SweeterSwift\n\u003cimg align=\"right\" src=\"Screenshots/SweeterSwift.png\"\u003e\n\n[![Swift Version][swift-image]][swift-url]\n[![Build Status][travis-image]][travis-url]\n[![License][license-image]][license-url]\n[![CocoaPods Compatible](https://img.shields.io/cocoapods/v/SweeterSwift.svg)](https://img.shields.io/cocoapods/v/SweeterSwift.svg)  \n[![Platform](https://img.shields.io/cocoapods/p/SweeterSwift.svg?style=flat)](http://cocoapods.org/pods/SweeterSwift)\n[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)\n\nExtensions and syntactic sugar to enrich the Swift standard library, iOS frameworks, and [SwifterSwift](https://github.com/SwifterSwift/SwifterSwift).\n\n## Installation\n\n### CocoaPods:\n\n```ruby\npod 'SweeterSwift'\n```\n\n### Swift Package Manager:\n\n```swift\ndependencies: [\n    .package(url: \"https://github.com/yonat/SweeterSwift\", from: \"1.2.6\")\n]\n```\n\n## Usage\n\n* [Auto Layout](#auto-layout)\n* [Bundle](#bundle)\n* [Codable](#codable)\n* [DateFormatter](#dateformatter)\n* [NotificationCenter](#notificationcenter)\n* [NSAttributedString](#nsattributedstring)\n* [NSManagedObjectContext](#nsmanagedobjectcontext)\n* [String](#string)\n* [Swift Standard Library](#swift-standard-library)\n* [TimeInterval](#timeinterval)\n* [UIApplication](#uiapplication)\n* [UILabel / UITextView](#uilabel-uitextview)\n* [UIStackView](#uistackview)\n* [UIView](#uiview)\n\n\n### Auto Layout\n\nAdd button at the center of view:\n\n```swift\nview.addConstrainedSubview(button, constrain: .centerX, .centerY)\n```\n\nPut label over textField:\n\n```swift\nview.constrain(label, at: .leading, to: textField)\nview.constrain(textField, at: .top, to: label, at: .bottom, diff: 8)\n```\n\nAdd child view controller covering all but the bottom margin:\n\n```swift\naddConstrainedChild(vc, constrain: .bottomMargin, .top, .left, .right)\n```\n\n### Bundle\n\nApp name with reasonable fallback to process name:\n\n```swift\nlet appName = Bundle.main.name\n```\n\nApp info string with name, version, and build number:\n\n```swift\nlet appInfo = Bundle.main.infoString // \"MyApp 1.0 #42\"\n```\n\n### Codable\n\nCreate object from a dictionary:\n\n```swift\nlet decodableObject = MyDecodableClass(dictionary: aDictionary)\n```\n\nExport object to a dictionary:\n\n```swift\nlet aDictionary = encodableObject.dictionary\n```\n\n### DateFormatter\n\nCreate with format:\n\n```swift\nlet dateFormatter = DateFormatter(format: \"cccc, MMMM dd\")\n```\n\n### NotificationCenter\n\nPost a local notification using `NotificationCenter.default`:\n\n```swift\nnotify(notificationName, userInfo: infoDictionary)\n```\n\nRespond to a local notification from `NotificationCenter.default`:\n\n```swift\nobserveNotification(notificationName, selector: #selector(someFunc))\n```\n\n### NSAttributedString\n\nCreate from HTML:\n\n```swift\nlet attributedString = NSAttributedString(htmlString: \"Hello, \u003cb\u003eworld\u003c/b\u003e!\")\n```\n\nTurn a substring into a link:\n\n```swift\nmutableAttributedString.link(anchorText: \"Hello\", url: \"https://ootips.org\")\n```\n\n### NSManagedObjectContext\n\nDump contents to console for debugging:\n\n```swift\nmanagedObjectContext.printAllObjects()\n```\n\nCreate a copy of the store for backup or for using later as initial setup:\n\n```swift\nmanagedObjectContext.backupStore()\n```\n\n### String\n\nSeparate CamelCase into capitalized words:\n\n```swift\nlet words = \"winterIsComing\".unCamelCased // \"Winter Is Coming\"\n```\n\nChange CamelCase into snake_case:\n\n```swift\nlet key = \"winterIsComing\".camelToSnakeCased // \"winter_is_coming\"\n```\n\n### Swift Standard Library\n\nIndex of current enum case in `allCases`:\n\n```swift\nlet index = MyEnum.someCase.index\n```\n\nUnwrap collection, shorthand for `compactMap { $0 }`:\n\n```swift\nlet nonOptionals = optionalsCollection.compact\n```\n\nAvoid retain cycles when passing a member function as an @escaping closure:\n\n```swift\nvar closure = weak(self, in: MyClass.someFunction)\n```\n\n### TimeInterval\n\nStandard time intervals:\n\n```swift\nlet myInterval: TimeInterval = .year + .month + .week + .day + .hour + .minute\n```\n\n### UIApplication\n\nFind the top-most view controller:\n\n```swift\nlet topVC = UIApplication.topViewController()\n```\n\nPresent modal over the top view controller:\n\n```swift\nUIApplication.present(modalVC)\n```\n\n### UILabel / UITextView\n\nCreate a label with links by using a `UITextView` to auto-detect links and simulate `UILabel` appearance:\n\n```swift\nlet hyperlinkedLabel = UITextView(simulatedLabelWithLinksInText: \"More at https://ootips.org\")\n```\n\n### UIStackView\n\nRemove an arranged subview from the view hierarchy, not just the stack arrangement:\n\n```swift\nstackView.removeArrangedSubviewCompletely(subview)\n```\n\nRemove all arranged subviews from the view hierarchy, not just the stack arrangement:\n\n```swift\nstackView.removeAllArrangedSubviewsCompletely()\n```\n\n### UIView\n\nSearch the view hierarchy recursively for a subview that meets a condition:\n\n```swift\nlet blueSubview = view.viewInHierarchy(where { $0.backgroundColor == .blue })\n```\n\nSearch the view hierarchy recursively for a subview with a specific class:\n\n```swift\nlet button = view.viewWithClass(UIButton.self)\n```\n\n\n## Meta\n\n[@yonatsharon](https://twitter.com/yonatsharon)\n\n[https://github.com/yonat/SweeterSwift](https://github.com/yonat/SweeterSwift)\n\n[swift-image]:https://img.shields.io/badge/swift-5.0-orange.svg\n[swift-url]: https://swift.org/\n[license-image]: https://img.shields.io/badge/License-MIT-blue.svg\n[license-url]: LICENSE.txt\n[travis-image]: https://img.shields.io/travis/dbader/node-datadog-metrics/master.svg?style=flat-square\n[travis-url]: https://travis-ci.org/dbader/node-datadog-metrics\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyonat%2Fsweeterswift","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyonat%2Fsweeterswift","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyonat%2Fsweeterswift/lists"}