{"id":15038025,"url":"https://github.com/mandon5/xcode-codesnippets","last_synced_at":"2026-04-07T13:31:38.908Z","repository":{"id":216516506,"uuid":"212287941","full_name":"ManDon5/Xcode-CodeSnippets","owner":"ManDon5","description":"Some useful Code Snippets for Xcode","archived":false,"fork":false,"pushed_at":"2020-05-06T12:10:31.000Z","size":709,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-13T13:13:53.287Z","etag":null,"topics":["code-snippet","code-snippets","swift","swift4","swift5","xcode","xcode10","xcode11"],"latest_commit_sha":null,"homepage":null,"language":"Makefile","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/ManDon5.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"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":"2019-10-02T08:17:15.000Z","updated_at":"2020-04-29T12:02:09.000Z","dependencies_parsed_at":"2024-01-10T18:35:20.923Z","dependency_job_id":null,"html_url":"https://github.com/ManDon5/Xcode-CodeSnippets","commit_stats":null,"previous_names":["mandon5/xcode-codesnippets"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ManDon5%2FXcode-CodeSnippets","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ManDon5%2FXcode-CodeSnippets/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ManDon5%2FXcode-CodeSnippets/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ManDon5%2FXcode-CodeSnippets/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ManDon5","download_url":"https://codeload.github.com/ManDon5/Xcode-CodeSnippets/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243410446,"owners_count":20286396,"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":["code-snippet","code-snippets","swift","swift4","swift5","xcode","xcode10","xcode11"],"created_at":"2024-09-24T20:36:51.282Z","updated_at":"2025-12-29T13:21:17.712Z","avatar_url":"https://github.com/ManDon5.png","language":"Makefile","readme":"# Xcode Code Snippets\r\n\r\nSome useful Code Snippets for your Xcode. It generates you templates for the following cases:\r\n\r\n  - [CollectionView Delegate and DataSource](#collectionview-delegate-and-datasource)\r\n  - [CollectionView configuration](#collectionview-configuration)\r\n  - [Constants](#constants)\r\n  - [Dequeue TableView Cell](#dequeue-tableview-cell)\r\n  - [Disable SwiftLint rule](#disable-swiftlint-rule)\r\n  - [Load data from plist file](#load-data-from-plist-file)\r\n  - [TableView configuration](#tableview-configuration)\r\n  - [TableView Delegate and DataSource](#tableview-delegate-and-datasource)\r\n\r\n![Screen](https://github.com/ManDon5/Xcode-CodeSnippets/blob/master/Screen.png)\r\n\r\n## Installation\r\n\r\nRun the following command of the make-file in Terminal:\r\n\r\n```sh\r\n$ make install_snippets\r\n```\r\n\r\nPlease restart Xcode after installation.\r\n\r\n## Uninstallation\r\n\r\nRun the following command of the make-file in Terminal:\r\n\r\n```sh\r\n$ make uninstall_snippets\r\n```\r\n\r\nPlease restart Xcode after uninstallation.\r\n\r\n\u003cbr/\u003e\r\n\r\n## Overview\r\n\r\n### CollectionView Delegate and DataSource\r\n\r\n| Configuration ||\r\n| --- | --- |\r\n| Title | CollectionView Delegate and DataSource |\r\n| Summary | Creates the extensions for collectionView Delegate and DataSource with a default implementation of the most used methods. |\r\n| Platform | All |\r\n| Language | Swift |\r\n| Completion Shortcut | collectionDelDat |\r\n| Completion Scopes | TopLevel |\r\n\r\n#### Code\r\n\r\n```swift\r\nextension \u003c#ViewController#\u003e: UICollectionViewDelegate {\r\n    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {\r\n\r\n    }\r\n}\r\n\r\nextension \u003c#ViewController#\u003e: UICollectionViewDataSource {\r\n    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -\u003e Int {\r\n        return \u003c#numberOfItemsInSection#\u003e\r\n    }\r\n\r\n    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -\u003e UICollectionViewCell {\r\n        switch indexPath.section {\r\n        case \u003c#section#\u003e:\r\n            return contentCollectionViewCell(for: indexPath)\r\n        default:\r\n            return UICollectionViewCell()\r\n        }\r\n    }\r\n\r\n    private func contentCollectionViewCell(for indexPath: IndexPath) -\u003e UICollectionViewCell {\r\n        if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: \u003c#cellIdentifier#\u003e, for: indexPath) as? \u003c#UICollectionViewCell#\u003e {\r\n            cell.\u003c#property#\u003e = \u003c#value#\u003e\r\n            return cell\r\n        }\r\n        return UICollectionViewCell()\r\n    }\r\n\r\n    private func noContentCollectionViewCell(for indexPath: IndexPath) -\u003e UICollectionViewCell {\r\n        if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: \u003c#cellIdentifier#\u003e, for: indexPath) as? \u003c#UICollectionViewCell#\u003e {\r\n            cell.\u003c#property#\u003e = \u003c#value#\u003e\r\n            return cell\r\n        }\r\n        return UICollectionViewCell()\r\n    }\r\n}\r\n```\r\n\r\n\u003c/br\u003e\r\n\r\n### CollectionView configuration\r\n\r\n| Configuration ||\r\n| --- | --- |\r\n| Title | CollectionView Configuration |\r\n| Summary | Creates a private method with a default configuration for a collectionView. |\r\n| Platform | All |\r\n| Language | Swift |\r\n| Completion Shortcut | configCollection |\r\n| Completion Scopes | ClassImplementation |\r\n\r\n#### Code\r\n\r\n```swift\r\nprivate func configureCollectionView() {\r\n        collectionView.delegate = self\r\n        collectionView.dataSource = self\r\n\r\n        let nib = UINib(nibName: \u003c#nibName#\u003e, bundle: nil)\r\n        let noContentNib = UINib(nibName: \u003c#noContentNibName#\u003e, bundle: nil)\r\n        collectionView.register(nib, forCellWithReuseIdentifier: \u003c#reuseIdentifier#\u003e)\r\n        collectionView.register(noContentNib, forCellWithReuseIdentifier: \u003c#noContentReuseIdentifier#\u003e)\r\n\r\n        collectionView.isScrollEnabled = \u003c#Bool#\u003e\r\n    }\r\n```\r\n\r\n\u003cbr/\u003e\r\n\r\n### Constants\r\n\r\n| Configuration ||\r\n| --- | --- |\r\n| Title | Constants |\r\n| Summary | Creates the constants enum which should contain all constants of a class. |\r\n| Platform | All |\r\n| Language | Swift |\r\n| Completion Shortcut | consts |\r\n| Completion Scopes | ClassImplementation |\r\n\r\n#### Code\r\n\r\n```swift\r\nenum Constants {\r\n    static let \u003c#constantName#\u003e: \u003c#T#\u003e = \u003c#value#\u003e\r\n}\r\n```\r\n\r\n\u003cbr/\u003e\r\n\r\n### Dequeue TableView Cell\r\n\r\n| Configuration ||\r\n| --- | --- |\r\n| Title | Dequeue TableView Cell |\r\n| Summary | Creates a default body for dequeueing a tableView cell. |\r\n| Platform | All |\r\n| Language | Swift |\r\n| Completion Shortcut | dequeueCell |\r\n| Completion Scopes | CodeExpression|\r\n||TopLevel|\r\n\r\n#### Code\r\n\r\n```swift\r\nif let cell = tableView.dequeueReusableCell(withIdentifier: \u003c#cellIdentifier#\u003e, for: indexPath) as? \u003c#UITableViewCell#\u003e {\r\n    cell.\u003c#property#\u003e = \u003c#value#\u003e\r\n    return cell\r\n}\r\nreturn UITableViewCell()\r\n```\r\n\r\n\u003cbr/\u003e\r\n\r\n### Disable SwiftLint rule\r\n\r\n| Configuration ||\r\n| --- | --- |\r\n| Title | Disable next SwiftLint rule |\r\n| Summary | Disables the next specific SwiftLint rule. |\r\n| Platform | All |\r\n| Language | Swift |\r\n| Completion Shortcut | lint |\r\n| Completion Scopes | StringOrComment |\r\n\r\n#### Code\r\n\r\n```swift\r\n// swiftlint:disable:next \u003c#rule#\u003e\r\n```\r\n\r\n\u003cbr/\u003e\r\n\r\n### Load data from plist file\r\n\r\n| Configuration ||\r\n| --- | --- |\r\n| Title | Load data from plist |\r\n| Summary | Decodes a plist file. |\r\n| Platform | All |\r\n| Language | Swift |\r\n| Completion Shortcut | plist |\r\n| Completion Scopes | ClassImplementation |\r\n\r\n#### Code\r\n\r\n```swift\r\nfunc readDataFromPlist() -\u003e \u003c#T: Decodable.Protocol#\u003e? {\r\n    if let url = Bundle.main.url(forResource: \"Info\", withExtension: \"plist\"), let data = try? Data(contentsOf: url) {\r\n        do {\r\n            return try PropertyListDecoder().decode(\u003c#T: Decodable.Protocol#\u003e.self, from: data)\r\n        } catch {\r\n            print(error)\r\n            return nil\r\n        }\r\n    } else {\r\n        return nil\r\n    }\r\n}\r\n```\r\n\r\n\u003cbr/\u003e\r\n\r\n### TableView configuration\r\n\r\n| Configuration ||\r\n| --- | --- |\r\n| Title | TableView Configuration |\r\n| Summary | Creates a private method with a default configuration for a tableView with pull to refresh. |\r\n| Platform | All |\r\n| Language | Swift |\r\n| Completion Shortcut | configTable |\r\n| Completion Scopes | ClassImplementation |\r\n\r\n#### Code\r\n\r\n```swift\r\nprivate let refreshControl = UIRefreshControl()\r\n\r\nprivate func configureTableView() {\r\n    tableView.delegate = self\r\n    tableView.dataSource = self\r\n\r\n    let nib = UINib(nibName: \u003c#nibName#\u003e, bundle: nil)\r\n    let noContentNib = UINib(nibName: \u003c#noContentNibName#\u003e, bundle: nil)\r\n    tableView.register(nib, forCellReuseIdentifier: \u003c#reuseIdentifier#\u003e)\r\n    tableView.register(noContentNib, forCellReuseIdentifier: \u003c#noContentReuseIdentifier#\u003e)\r\n\r\n    tableView.estimatedRowHeight = \u003c#estimatedRowHeight#\u003e\r\n    tableView.rowHeight = UITableView.automaticDimension\r\n\r\n    if #available(iOS 10.0, *) {\r\n        tableView.refreshControl = refreshControl\r\n    } else {\r\n        tableView.addSubview(refreshControl)\r\n    }\r\n    refreshControl.addTarget(self, action: #selector(refresh(_:)), for: .valueChanged)\r\n}\r\n\r\n@objc\r\nprivate func refresh(_ sender: Any) {\r\n\r\n}\r\n```\r\n\r\n\u003cbr/\u003e\r\n\r\n### TableView Delegate and DataSource\r\n\r\n| Configuration ||\r\n| --- | --- |\r\n| Title | TableView Delegate and DataSource |\r\n| Summary | Creates the extensions for tableView Delegate and DataSource with a default implementation of the most used methods. |\r\n| Platform | All |\r\n| Language | Swift |\r\n| Completion Shortcut | tableDelDat |\r\n| Completion Scopes | TopLevel |\r\n\r\n#### Code\r\n\r\n```swift\r\nextension \u003c#ViewController#\u003e: UITableViewDelegate {\r\n    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {\r\n\r\n    }\r\n}\r\n\r\nextension \u003c#ViewController#\u003e: UITableViewDataSource {\r\n    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -\u003e Int {\r\n        return \u003c#numberOfRowsInSection#\u003e\r\n    }\r\n\r\n    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -\u003e UITableViewCell {\r\n        switch indexPath.section {\r\n        case \u003c#section#\u003e:\r\n            return contentTableViewCell(for: indexPath)\r\n        default:\r\n            return UITableViewCell()\r\n        }\r\n    }\r\n\r\n    private func contentTableViewCell(for indexPath: IndexPath) -\u003e UITableViewCell {\r\n        if let cell = tableView.dequeueReusableCell(withIdentifier: \u003c#cellIdentifier#\u003e, for: indexPath) as? \u003c#UITableViewCell#\u003e {\r\n            cell.\u003c#property#\u003e = \u003c#value#\u003e\r\n            return cell\r\n        }\r\n        return UITableViewCell()\r\n    }\r\n\r\n    private func noContentTableViewCell() -\u003e UITableViewCell {\r\n        if let cell = tableView.dequeueReusableCell(withIdentifier: \u003c#cellIdentifier#\u003e) as? \u003c#UITableViewCell#\u003e {\r\n            cell.\u003c#property#\u003e = \u003c#value#\u003e\r\n            return cell\r\n        }\r\n        return UITableViewCell()\r\n    }\r\n}\r\n```\r\n\r\n\u003cbr/\u003e\r\n\r\n## License\r\n\r\nXcode Code Snippets is released under the MIT License. See [LICENSE](LICENSE.md) for details.\r\n\r\n## Contribution\r\n\r\nAuthor: [ManDon5](https://github.com/ManDon5)\r\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmandon5%2Fxcode-codesnippets","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmandon5%2Fxcode-codesnippets","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmandon5%2Fxcode-codesnippets/lists"}