{"id":13908357,"url":"https://github.com/derekcoder/SwiftDevHints","last_synced_at":"2025-07-18T07:30:58.727Z","repository":{"id":62456492,"uuid":"97292872","full_name":"derekcoder/SwiftDevHints","owner":"derekcoder","description":"A very useful set of development tools for Swift.","archived":false,"fork":false,"pushed_at":"2020-06-03T12:15:57.000Z","size":1118,"stargazers_count":47,"open_issues_count":0,"forks_count":8,"subscribers_count":8,"default_branch":"master","last_synced_at":"2024-04-09T11:59:15.122Z","etag":null,"topics":["devtools","ios","ios-swift","swift","swiftdevhints","tools"],"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/derekcoder.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-07-15T04:49:06.000Z","updated_at":"2023-01-12T12:48:12.000Z","dependencies_parsed_at":"2022-11-02T00:16:51.532Z","dependency_job_id":null,"html_url":"https://github.com/derekcoder/SwiftDevHints","commit_stats":null,"previous_names":[],"tags_count":61,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/derekcoder%2FSwiftDevHints","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/derekcoder%2FSwiftDevHints/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/derekcoder%2FSwiftDevHints/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/derekcoder%2FSwiftDevHints/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/derekcoder","download_url":"https://codeload.github.com/derekcoder/SwiftDevHints/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226371921,"owners_count":17614605,"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":["devtools","ios","ios-swift","swift","swiftdevhints","tools"],"created_at":"2024-08-06T23:02:40.176Z","updated_at":"2024-11-25T17:30:53.984Z","avatar_url":"https://github.com/derekcoder.png","language":"Swift","readme":"# SwiftDevHints\n\n[![Version](https://img.shields.io/cocoapods/v/SwiftDevHints.svg?style=flat)](http://cocoapods.org/pods/SwiftDevHints)\n[![License](https://img.shields.io/cocoapods/l/SwiftDevHints.svg?style=flat)](http://cocoapods.org/pods/SwiftDevHints)\n[![Platform](https://img.shields.io/cocoapods/p/SwiftDevHints.svg?style=flat)](http://cocoapods.org/pods/SwiftDevHints)\n\n## Requirements\n\n- iOS 10.0+ / macOS 10.12+ / watchOS 4.0+\n- Swift 5\n\n## Installation\n\nTapticc is available through [CocoaPods](https://cocoapods.org). To install\nit, simply add the following line to your Podfile:\n\n```ruby\npod 'SwiftDevHints'\n```\n\n## Usage\n\n* String Extensions\n* Collection Optional Extensions\n* Optional Extensions\n* Collection Extensions\n* UITableView Extensions\n* UserDefaults Extensions\n* UIColor Extensions\n* Bundle Extensions\n* Date Extensions\n\n### String Extensions\n\nThe safe way to return string slice\n```swift\nlet string = \"Hello, Swift!\"\nstring[safe: 0..\u003c5]  // \"Hello\"\nstring[safe: 0...4]  // \"Hello\"\nstring[safe: 0..\u003c14] // nil\n```\n\n`intBaseHex`\nGet int value form hex string\n```swift\nprint(\"FF\".intBaseHex)  // 255\nprint(\"0xFF\".intBaseHex)  // 255\n```\n\n`trimmed()`\n```swift\n\" hello world \\n\\t\".trimmed()  // \"hello world\"\n```\n\n`trimming()`\n```swift\nvar string = \" hello world \\n\\t\"\nstring.trimming()\nstring  // \"hello world\"\n```\n\n`isBlank`\n```swift\n\" \\n\\t \".isBlank  // true\n```\n\n`nilIfEmpty`\n```swift\n\"\".nilIfEmpty  // nil\n```\n\n### Collection Optional Extensions\n\n`isNilOrEmpty`\n```swift\n\"\".isNilOrEmpty  // true\n([] as? [String]).isNilOrEmpty  // true\n```\n\n### Optional Extensions\n\n`isNone` \u0026 `isSome`\n```swift\n\"hello\".isNone  // false\n\"hello\".isSome  // true\n\nvar name: String? = nil\nname.isNone  // true\nname.isSome  // false\n```\n\n`noneDo` \u0026 `someDo`\n```swift\nvar name: String? = nil\n\nname.noneDo {\n    print(\"name is nil\")\n}\n\nname.someDo {\n    print(\"name has a value \\($0)\")\n}\n```\n\n### Collection Extensions\n\nThe safe way to return element at specified index\n```swift\nlet animals = [\"Zebra\", \"Giraffe\", \"Tiger\"]\nlet zebra = animals[safe: 0] // \"Zebra\"\nlet lion = animals[safe: 3] // nil\n```\n\n### UITableView Extensions\n\nRegister \u0026 Dequeue UITableViewCell\n```swift\nclass UserCell: UITableViewCell, NibReusable { }\n\ntableView.register(UserCell.self)\nlet cell: UserCell = tableView.dequeueReusableCell(for: indexPath)\n```\n\n### UICollectionView Extensions\n\nRegister \u0026 Dequeue UICollectionViewCell\n```swift\nclass PhotoCell: UICollectionViewCell, NibReusable { }\n\ncollectionView.register(PhotoCell.self)\nlet cell: PhotoCell = collectionView.dequeueReusableCell(for: indexPath)\n```\n\n### UserDefaults Extensions\n\nA safe way to use UserDefaults\n```swift\nextension UserDefaults.Name {\n    static let username: UserDefaults.Name = \"SwiftDevHints-Demo.Username\"\n    static let password: UserDefaults.Name = \"SwiftDevHints-Demo.Password\"\n}\n\n// Register Initial Value\nUserDefaults.standard.register(defaults: [.username: \"Unknown\"])\n\n// Set Value\nUserDefaults.standard.set(\"Derek\", forName: .username)\nUserDefaults.standard.set(\"12345\", forName: .password)\n\n// Get Value\nlet username = UserDefaults.standard.string(forName: .username)\nlet password = UserDefaults.standard.string(forName: .password)\n```\n\n### UIColor Extensions\n\nInitialize UIColor with RGB based 255\n```swift\nlet color = UIColor(red: 255, green: 32, blue: 171)\n```\n\nInitialize UIColor with RGB Hex String\n```swift\nlet color = UIColor(hexString: \"FF20AB\") \n```\n\nCreate a black or white UIColor object that constrasts to specified color.\n```swift\nlet color = UIColor(constrastingBlackOrWhiteColorOn: UIColor.green)\n```\n\nGet hexadecimal value string of this color (start with \"#\")\n```swift\nlet hexString = UIColor.red.hexString // #FF0000\n```\n\nGet RGB or HSBA components\n```swift\nlet rgb = UIColor.red.rgbComponents // (red: 255, green: 0, blue: 0)\nlet rgba = UIColor.red.rgbaComponents // (red: 1.0, green: 0.0, blue: 0.0, alpha: 1.0)\nlet hsba = UIColor.red.hsbaComponents // (hue: 0.0, saturation: 1.0, brightness: 1.0, alpha: 1.0)\n```\n\nGet random color\n```swift\nlet randomColor = UIColor.random\n```\n\n### Bundle Extensions\n\nConvenient methods to access Info.plist\n```swift\nlet bundle = Bundle.main\n\nlet displayName = bundle.displayName\nlet identifier = bundle.identifier\nlet version = bundle.version\nlet build = bundle.build\n\n// All keys\nprivate enum InfoPlistKey: String {\ncase name = \"CFBundleName\"\ncase displayName = \"CFBundleDisplayName\"\ncase developmentRegion = \"CFBundleDevelopmentRegion\"\ncase identifier = \"CFBundleIdentifier\"\ncase version = \"CFBundleShortVersionString\"\ncase build = \"CFBundleVersion\"\ncase packageType = \"CFBundlePackageType\"\n}\n```\n\n### Date Extensions\n\nSome convenient methods\n```swift\nlet today = Date()                   // December 17, 2017 at 5:54:46 PM GMT+8\nlet startOfToday = today.startOfDay  // December 17, 2017 at 12:00:00 AM GMT+8\nlet endOfToday = today.endOfDay      // December 17, 2017 at 11:59:59 PM GMT+8\nlet previousDay = today.previousDay  // December 16, 2017 at 5:54:46 PM GMT+8\nlet nextDay = today.nextDay          // December 18, 2017 at 5:54:46 PM GMT+8\n\n// December 14, 2017 at 5:54:46 PM GMT+8\n// December 15, 2017 at 5:54:46 PM GMT+8\n// December 16, 2017 at 5:54:46 PM GMT+8\nlet last3Days = today.lastDays(withCount: 3, includingToday: false)\n\n// December 17, 2017 at 5:54:46 PM GMT+8\n// December 18, 2017 at 5:54:46 PM GMT+8\n// December 19, 2017 at 5:54:46 PM GMT+8\nlet next3Days = today.nextDays(withCount: 3, includingToday: true)\n```\n\n## References\n\n- https://github.com/Luur/SwiftTips#1-safe-way-to-return-element-at-specified-index\n- https://github.com/onevcat/Kingfisher\n- https://github.com/AliSoftware/Reusable\n- https://github.com/andyyhope/nemo\n\n## Author\n\n- Twitter: [@derekcoder_](https://twitter.com/derekcoder_)\n- Weibo: [@derekcoder](https://weibo.com/u/6155322764)\n- Email: derekcoder@gmail.com\n\n## License\n\nSwiftDevHints is released under the MIT license. [See LICENSE](https://github.com/derekcoder/SwiftDevHints/blob/master/LICENSE) for details.\n","funding_links":[],"categories":["HarmonyOS"],"sub_categories":["Windows Manager"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fderekcoder%2FSwiftDevHints","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fderekcoder%2FSwiftDevHints","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fderekcoder%2FSwiftDevHints/lists"}