{"id":3283,"url":"https://github.com/ismetanin/XcodeCodeSnippets","last_synced_at":"2025-08-03T13:32:25.087Z","repository":{"id":81603464,"uuid":"98975266","full_name":"ismetanin/XcodeCodeSnippets","owner":"ismetanin","description":"Code snippets for Xcode.","archived":false,"fork":false,"pushed_at":"2020-06-05T15:41:47.000Z","size":75,"stargazers_count":34,"open_issues_count":0,"forks_count":6,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-12-06T20:58:39.071Z","etag":null,"topics":["codesnippets","snippets","swift","xcode","xcode-snippets","xcodesnippets"],"latest_commit_sha":null,"homepage":"","language":"Shell","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/ismetanin.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}},"created_at":"2017-08-01T07:56:36.000Z","updated_at":"2024-05-12T07:04:27.000Z","dependencies_parsed_at":null,"dependency_job_id":"2bea3ad5-d1ca-4347-a3cd-d405312f1427","html_url":"https://github.com/ismetanin/XcodeCodeSnippets","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ismetanin%2FXcodeCodeSnippets","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ismetanin%2FXcodeCodeSnippets/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ismetanin%2FXcodeCodeSnippets/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ismetanin%2FXcodeCodeSnippets/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ismetanin","download_url":"https://codeload.github.com/ismetanin/XcodeCodeSnippets/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":["codesnippets","snippets","swift","xcode","xcode-snippets","xcodesnippets"],"created_at":"2024-01-05T20:16:37.029Z","updated_at":"2024-12-07T01:30:46.114Z","avatar_url":"https://github.com/ismetanin.png","language":"Shell","funding_links":[],"categories":["Xcode","WebSocket","Shell"],"sub_categories":["Other Xcode","Other free courses"],"readme":"[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)\n\n# XcodeCodeSnippets\n\nA set of snippets for Xcode.\n\n## Requirements\n\nXcode 7.3.1 or later.\n\n## Installation\n\nTo install or update the snippets you need:\n\n* Quit Xcode\n* On the command line:\n\n```\ncd ~/Downloads\ngit clone https://github.com/ismetanin/XcodeCodeSnippets\nmkdir -p $HOME/Library/Developer/Xcode/UserData/CodeSnippets\ncp XcodeCodeSnippets/CodeSnippets/* $HOME/Library/Developer/Xcode/UserData/CodeSnippets\nrm -rf XcodeCodeSnippets\n```\n\n  Or if you have a cloned repository:\n\n* On the command line, cd into the directory with snippets and write `sh ./install.sh`\n\n## List of snippets\n\n### MARKs\n\nThere are MARKs for Swift and Objective-C. For Swift there is prefix before each `// MARK: -` and for Objective-C prefix is `#pragma mark -`.\n\nShortcuts are equal to snippet body for example for `// MARK: - Properties` shortcut is `Properties`.\n\n\u003cdetails\u003e\n  \u003csummary\u003eAvailable MARKs\u003c/summary\u003e\n  \u003cbr\u003e\n\n|Snippet|\n|---|\n|Just empty mark (`// MARK: - ` or `#pragma mark - `)     |\n|`Nested types`                                           |\n|`Constants`                                              |\n|`Subviews`                                               |\n|`NSLayoutConstraints`                                    |\n|`Properties`                                             |\n|`Public properties`                                      |\n|`Readonly properties`                                    |\n|`IBOutlets`                                              |\n|`Initialization and deinitialization`                    |\n|`UITableViewCell`                                        |\n|`UIViewController`                                       |\n|`Actions`                                                |\n|`IBActions`                                              |\n|`Public methods`                                         |\n|`Internal methods`                                       |\n|`Private methods`                                        |\n\u003c/details\u003e\n\n### Code\n\n* A template for creating TableViewAdapter, **shortcut:** `Table View Adapter`\n  \u003cdetails\u003e\n  \u003csummary\u003eCode\u003c/summary\u003e\n  \u003cbr\u003e\n\n   ```swift\n    import UIKit\n\n    protocol \u003c#Your#\u003eTableViewAdapterOutput {\n    }\n\n    final class \u003c#Your#\u003eTableViewAdapter: NSObject {\n        // MARK: - Properties\n\n        private let output: \u003c#Your#\u003eTableViewAdapterOutput\n\n        private var items: [String]\n        private var tableView: UITableView\n\n        // MARK: - Initialization and deinitialization\n\n        init(tableView: UITableView, output: \u003c#Your#\u003eTableViewAdapterOutput) {\n            self.output = output\n            self.tableView = tableView\n            self.items = []\n            super.init()\n            setupTable()\n        }\n\n        // MARK: - Internal methods\n\n        func configure(with items: [String]) {\n            self.items = items\n            tableView.reloadData()\n        }\n\n        // MARK: - Private methods\n\n        private func setupTable() {\n            tableView.delegate = self\n            tableView.dataSource = self\n            tableView.register(\n                UINib(nibName: String(describing: \u003c#Your#\u003eTableViewCell.self), bundle: nil),\n                forCellReuseIdentifier: String(describing: \u003c#Your#\u003eTableViewCell.self)\n            )\n        }\n    }\n\n    // MARK: - UITableViewDataSource\n\n    extension \u003c#Your#\u003eTableViewAdapter: UITableViewDataSource {\n        func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -\u003e Int {\n            return items.count\n        }\n\n        func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -\u003e UITableViewCell {\n            let cell = tableView.dequeueReusableCell(\n                withIdentifier: String(describing: \u003c#Your#\u003eTableViewCell.self),\n                for: indexPath\n            ) as? TableViewCell\n            cell?.backgroundColor = .red\n            return cell ?? \u003c#Your#\u003eUITableViewCell()\n        }\n    }\n\n    // MARK: - UITableViewDelegate\n\n    extension \u003c#Your#\u003eTableViewAdapter: UITableViewDelegate {\n        func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {\n            tableView.deselectRow(at: indexPath, animated: true)\n        }\n    }\n   ```\n\n  \u003c/details\u003e\n* A code block for creating user property in UserDefaults extension, **shortcut:** `Defaults Key`\n  \u003cdetails\u003e\n  \u003csummary\u003eCode\u003c/summary\u003e\n  \u003cbr\u003e\n\n   ```swift\n    var \u003c#defaultsKey#\u003e: \u003c#Type#\u003e {\n        get { return \u003c#typeof#\u003e(forKey: #function) }\n        set { set(newValue, forKey: #function) }\n    }\n   ```\n\n  \u003c/details\u003e\n* A code block for layouting child view anchors equal to the parent view anchors, **shortcut:** `Constraints - layout child as parent`\n  \u003cdetails\u003e\n  \u003csummary\u003eCode\u003c/summary\u003e\n  \u003cbr\u003e\n\n   ```swift\n    \u003c#childView#\u003e.translatesAutoresizingMaskIntoConstraints = false\n\n    NSLayoutConstraint.activate([\n        \u003c#childView#\u003e.topAnchor.constraint(equalTo: \u003c#parentView#\u003e.safeAreaLayoutGuide.topAnchor, constant: 0),\n        \u003c#childView#\u003e.bottomAnchor.constraint(equalTo: \u003c#parentView#\u003e.safeAreaLayoutGuide.bottomAnchor, constant: 0),\n        \u003c#childView#\u003e.leadingAnchor.constraint(equalTo: \u003c#parentView#\u003e.safeAreaLayoutGuide.leadingAnchor, constant: 0),\n        \u003c#childView#\u003e.trailingAnchor.constraint(equalTo: \u003c#parentView#\u003e.safeAreaLayoutGuide.trailingAnchor, constant: 0)\n        ])\n   ```\n\n  \u003c/details\u003e\n  \n* A code block for user property creating in NSNotification.Name extension, **shortcut:** `NSNotification Name`\n  \u003cdetails\u003e\n  \u003csummary\u003eCode\u003c/summary\u003e\n  \u003cbr\u003e\n\n   ```swift\n  static let \u003c#notificationName#\u003e = NSNotification.Name(\"\u003c#projectName#\u003e.notifications.\u003c#notificationName#\u003e\")\n   ```\n\n  \u003c/details\u003e\n  \n* A code block for creating template comments for unit test, **shortcut:** `testtemplate`\n  \u003cdetails\u003e\n  \u003csummary\u003eCode\u003c/summary\u003e\n  \u003cbr\u003e\n\n   ```swift\n  // given\n\n  // when\n\n  // then\n\n   ```\n\n  \u003c/details\u003e\n  \n* A code block for creating template constants enum, **shortcut:** `Constants enum`\n  \u003cdetails\u003e\n  \u003csummary\u003eCode\u003c/summary\u003e\n  \u003cbr\u003e\n\n   ```swift\n    // MARK: - Nested types\n\n    private enum Constants {\n\n    }\n    ```\n\n   \u003c/details\u003e\n\n* A code block for creating keyboard notifications detector, **shortcut:** `Keyboard detector`\n  \u003cdetails\u003e\n  \u003csummary\u003eCode\u003c/summary\u003e\n  \u003cbr\u003e\n\n   ```swift\n  func addKeyboardObservers() {\n        NotificationCenter.default.addObserver(self,\n                                               selector: #selector(keyboardWillShow),\n                                               name: UIResponder.keyboardWillShowNotification,\n                                               object: nil)\n        NotificationCenter.default.addObserver(self,\n                                               selector: #selector(keyboardWillHide),\n                                               name: UIResponder.keyboardWillHideNotification,\n                                               object: nil)\n    }\n\n    @objc\n    func keyboardWillShow(notification: NSNotification) {\n        guard\n            let frame = notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue\n        else {\n            return\n        }\n    }\n\n    @objc\n    func keyboardWillHide() {\n\n    }\n   ```\n\n  \u003c/details\u003e\n\n### Author\n\nIvan Smetanin, smetanin23@yandex.ru\n\n### License\n\nXcodeCodeSnippets is available under the MIT license. See the [LICENSE](https://github.com/ismetanin/XcodeCodeSnippets/blob/master/LICENSE) file for more info.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fismetanin%2FXcodeCodeSnippets","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fismetanin%2FXcodeCodeSnippets","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fismetanin%2FXcodeCodeSnippets/lists"}