{"id":3290,"url":"https://github.com/onmyway133/SwiftSnippets","last_synced_at":"2025-08-03T13:32:27.891Z","repository":{"id":69039214,"uuid":"62753092","full_name":"onmyway133/SwiftSnippets","owner":"onmyway133","description":"🍮 A collection of Swift snippets to be used in Xcode","archived":false,"fork":false,"pushed_at":"2020-04-14T14:03:46.000Z","size":23,"stargazers_count":164,"open_issues_count":0,"forks_count":21,"subscribers_count":14,"default_branch":"master","last_synced_at":"2024-11-27T21:02:25.193Z","etag":null,"topics":["ios","macos","snippet","swift"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/onmyway133.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2016-07-06T21:02:23.000Z","updated_at":"2024-08-10T20:33:14.000Z","dependencies_parsed_at":"2023-05-05T01:16:24.443Z","dependency_job_id":null,"html_url":"https://github.com/onmyway133/SwiftSnippets","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/onmyway133%2FSwiftSnippets","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onmyway133%2FSwiftSnippets/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onmyway133%2FSwiftSnippets/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onmyway133%2FSwiftSnippets/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/onmyway133","download_url":"https://codeload.github.com/onmyway133/SwiftSnippets/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228548567,"owners_count":17935221,"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":["ios","macos","snippet","swift"],"created_at":"2024-01-05T20:16:37.219Z","updated_at":"2024-12-07T01:30:47.911Z","avatar_url":"https://github.com/onmyway133.png","language":"Shell","funding_links":[],"categories":["Reference","\u003ca id=\"8c5a692b5d26527ef346687e047c5c21\"\u003e\u003c/a\u003e收集"],"sub_categories":["React-Like","Other Xcode"],"readme":"# Swift Snippets\n\n❤️ Support my app ❤️ \n\n- [Push Hero - pure Swift native macOS application to test push notifications](https://www.producthunt.com/posts/push-hero-2)\n- [PastePal - Pasteboard, note and shortcut manager](https://www.producthunt.com/posts/pastepal)\n- [Frame recorder - Recorder gif and video with frame](https://www.producthunt.com/posts/frame-recorder)\n- [Alias - App and file shortcut manager](https://www.producthunt.com/posts/alias-shortcut-manager)\n- [Other apps](https://onmyway133.github.io/projects/)\n\n❤️❤️😇😍🤘❤️❤️\n\n\nA collection of Swift snippets to be used in Xcode\n\n## Usage\n\n- swifttrycatch\n\n```swift\ndo {\n  try \u003c#code#\u003e\n} catch \u003c#errortype#\u003e {\n  \u003c#code#\u003e\n} catch \u003c#errortype#\u003e {\n  \u003c#code#\u003e\n}\n```\n\n- swiftassociatedobject\n\n```swift\nprivate struct AssociatedKeys {\n  static var \u003c#name#\u003e = \"\u003c#name#\u003e\"\n}\n\nvar \u003c#name#\u003e: String? {\n  get {\n    return objc_getAssociatedObject(self, \u0026AssociatedKeys.\u003c#name#\u003e) as? String\n  }\n\n  set {\n    if let newValue = newValue {\n      objc_setAssociatedObject(self, \u0026AssociatedKeys.\u003c#name#\u003e, newValue as String?,\n        .OBJC_ASSOCIATION_RETAIN_NONATOMIC\n      )\n    }\n  }\n}\n```\n\n- swiftavailable\n\n```swift\n@available(iOS 7, *)\n```\n\n- swiftcheckavailability\n\n```swift\nif #available(iOS 9, *) {\n    \u003c#API available statements#\u003e\n} else if #available(macOS 10.12, *) {\n    \u003c#API available statements#\u003e\n} else {\n    \u003c#fallback statements#\u003e\n}\n```\n\n- swiftcheckversion\n\n```swift\n#if swift(\u003e=3.0)\n    \u003c#code#\u003e\n#elseif swift(\u003e=2.2)\n    \u003c#code#\u003e\n#elseif swift(\u003e=2.1)\n    \u003c#code#\u003e\n#endif\n```\n\n- swiftcheckplatform\n\n```swift\n#if os(iOS) || os(tvOS)\n  \u003c#code#\u003e\n#elseif os(watchOS)\n  \u003c#code#\u003e\n#elseif os(OSX)\n  \u003c#code#\u003e\n#endif\n```\n\n- swiftdispatchafter\n\n```swift\nDispatchQueue.main.asyncAfter(deadline: .now() + \u003c#time#\u003e) {\n  \u003c#code#\u003e\n}\n```\n\n- swiftdispatchasync\n\n```swift\nDispatchQueue.global(qos: .background).async {\n  \u003c#code#\u003e\n}\n```\n\n- swiftdispatchonce\n\n```swift\nlet \u003c#name#\u003e: \u003c#type#\u003e = {\n  return \u003c#code#\u003e\n}()\n```\n\n- swiftinitcoder\n\n```swift\npublic required init?(coder aDecoder: NSCoder) {\n  fatalError(\"init(coder:) has not been implemented\")\n}\n```\n\n- swiftmark\n\n```swift\n// MARK: - \u003c#section#\u003e\n```\n\n- swiftsubscript\n\n```swift\nsubscript(\u003c#name#\u003e: \u003c#type#\u003e) -\u003e \u003c#type#\u003e {\n  get {\n    return \u003c#value#\u003e\n  }\n  set(newValue) {\n      \u003c#code#\u003e\n  }\n}\n```\n\n- swiftguardself\n\n```swift\nguard let `self` = self else {\n  return\n}\n```\n\n- swiftuitableviewdatasource\n ```swift\nfunc numberOfSections(in tableView: UITableView) -\u003e Int {\n  return \u003c#count#\u003e\n}\n\nfunc tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -\u003e Int {\n  return \u003c#count#\u003e\n}\n\nfunc tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -\u003e UITableViewCell {\n  \u003c#code#\u003e\n}\n ```\n\n- swiftuicollectionviewdatasource\n\n```swift\nfunc numberOfSections(in collectionView: UICollectionView) -\u003e Int {\n  return \u003c#count#\u003e\n}\n\nfunc collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -\u003e Int {\n  return \u003c#count#\u003e\n}\n\nfunc collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -\u003e UICollectionViewCell {\n  \u003c#code#\u003e\n}\n```\n\n- swiftuipickerviewdatasource\n\n```swift\nfunc numberOfComponents(in pickerView: UIPickerView) -\u003e Int {\n  return \u003c#count#\u003e\n}\n\nfunc pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -\u003e Int {\n  return \u003c#count#\u003e\n}\n```\n\n## Installation\n\n### Manual\n\nDrag `codesnippet` files from `Snippets` into `/Library/Developer/Xcode/UserData/CodeSnippets`\n\n### Automatic\n\nRun this in your terminal\n\n```\ncurl -fsSL https://raw.githubusercontent.com/hyperoslo/SwiftSnippets/master/install.sh | sh\n```\n\n## Author\n\n- Khoa Pham, onmyway133@gmai.com\n\n## Credit\n\n- Hyper Interaktiv AS, ios@hyper.no\n\n## License\n\n**SwiftSnippets** 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%2Fonmyway133%2FSwiftSnippets","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fonmyway133%2FSwiftSnippets","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fonmyway133%2FSwiftSnippets/lists"}