Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mandon5/xcode-codesnippets
Some useful Code Snippets for Xcode
https://github.com/mandon5/xcode-codesnippets
code-snippet code-snippets swift swift4 swift5 xcode xcode10 xcode11
Last synced: 26 days ago
JSON representation
Some useful Code Snippets for Xcode
- Host: GitHub
- URL: https://github.com/mandon5/xcode-codesnippets
- Owner: ManDon5
- License: mit
- Created: 2019-10-02T08:17:15.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2020-05-06T12:10:31.000Z (over 4 years ago)
- Last Synced: 2024-10-12T14:40:53.025Z (26 days ago)
- Topics: code-snippet, code-snippets, swift, swift4, swift5, xcode, xcode10, xcode11
- Language: Makefile
- Size: 692 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Xcode Code Snippets
Some useful Code Snippets for your Xcode. It generates you templates for the following cases:
- [CollectionView Delegate and DataSource](#collectionview-delegate-and-datasource)
- [CollectionView configuration](#collectionview-configuration)
- [Constants](#constants)
- [Dequeue TableView Cell](#dequeue-tableview-cell)
- [Disable SwiftLint rule](#disable-swiftlint-rule)
- [Load data from plist file](#load-data-from-plist-file)
- [TableView configuration](#tableview-configuration)
- [TableView Delegate and DataSource](#tableview-delegate-and-datasource)![Screen](https://github.com/ManDon5/Xcode-CodeSnippets/blob/master/Screen.png)
## Installation
Run the following command of the make-file in Terminal:
```sh
$ make install_snippets
```Please restart Xcode after installation.
## Uninstallation
Run the following command of the make-file in Terminal:
```sh
$ make uninstall_snippets
```Please restart Xcode after uninstallation.
## Overview
### CollectionView Delegate and DataSource
| Configuration ||
| --- | --- |
| Title | CollectionView Delegate and DataSource |
| Summary | Creates the extensions for collectionView Delegate and DataSource with a default implementation of the most used methods. |
| Platform | All |
| Language | Swift |
| Completion Shortcut | collectionDelDat |
| Completion Scopes | TopLevel |#### Code
```swift
extension <#ViewController#>: UICollectionViewDelegate {
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {}
}extension <#ViewController#>: UICollectionViewDataSource {
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return <#numberOfItemsInSection#>
}func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
switch indexPath.section {
case <#section#>:
return contentCollectionViewCell(for: indexPath)
default:
return UICollectionViewCell()
}
}private func contentCollectionViewCell(for indexPath: IndexPath) -> UICollectionViewCell {
if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: <#cellIdentifier#>, for: indexPath) as? <#UICollectionViewCell#> {
cell.<#property#> = <#value#>
return cell
}
return UICollectionViewCell()
}private func noContentCollectionViewCell(for indexPath: IndexPath) -> UICollectionViewCell {
if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: <#cellIdentifier#>, for: indexPath) as? <#UICollectionViewCell#> {
cell.<#property#> = <#value#>
return cell
}
return UICollectionViewCell()
}
}
```### CollectionView configuration
| Configuration ||
| --- | --- |
| Title | CollectionView Configuration |
| Summary | Creates a private method with a default configuration for a collectionView. |
| Platform | All |
| Language | Swift |
| Completion Shortcut | configCollection |
| Completion Scopes | ClassImplementation |#### Code
```swift
private func configureCollectionView() {
collectionView.delegate = self
collectionView.dataSource = selflet nib = UINib(nibName: <#nibName#>, bundle: nil)
let noContentNib = UINib(nibName: <#noContentNibName#>, bundle: nil)
collectionView.register(nib, forCellWithReuseIdentifier: <#reuseIdentifier#>)
collectionView.register(noContentNib, forCellWithReuseIdentifier: <#noContentReuseIdentifier#>)collectionView.isScrollEnabled = <#Bool#>
}
```
### Constants
| Configuration ||
| --- | --- |
| Title | Constants |
| Summary | Creates the constants enum which should contain all constants of a class. |
| Platform | All |
| Language | Swift |
| Completion Shortcut | consts |
| Completion Scopes | ClassImplementation |#### Code
```swift
enum Constants {
static let <#constantName#>: <#T#> = <#value#>
}
```
### Dequeue TableView Cell
| Configuration ||
| --- | --- |
| Title | Dequeue TableView Cell |
| Summary | Creates a default body for dequeueing a tableView cell. |
| Platform | All |
| Language | Swift |
| Completion Shortcut | dequeueCell |
| Completion Scopes | CodeExpression|
||TopLevel|#### Code
```swift
if let cell = tableView.dequeueReusableCell(withIdentifier: <#cellIdentifier#>, for: indexPath) as? <#UITableViewCell#> {
cell.<#property#> = <#value#>
return cell
}
return UITableViewCell()
```
### Disable SwiftLint rule
| Configuration ||
| --- | --- |
| Title | Disable next SwiftLint rule |
| Summary | Disables the next specific SwiftLint rule. |
| Platform | All |
| Language | Swift |
| Completion Shortcut | lint |
| Completion Scopes | StringOrComment |#### Code
```swift
// swiftlint:disable:next <#rule#>
```
### Load data from plist file
| Configuration ||
| --- | --- |
| Title | Load data from plist |
| Summary | Decodes a plist file. |
| Platform | All |
| Language | Swift |
| Completion Shortcut | plist |
| Completion Scopes | ClassImplementation |#### Code
```swift
func readDataFromPlist() -> <#T: Decodable.Protocol#>? {
if let url = Bundle.main.url(forResource: "Info", withExtension: "plist"), let data = try? Data(contentsOf: url) {
do {
return try PropertyListDecoder().decode(<#T: Decodable.Protocol#>.self, from: data)
} catch {
print(error)
return nil
}
} else {
return nil
}
}
```
### TableView configuration
| Configuration ||
| --- | --- |
| Title | TableView Configuration |
| Summary | Creates a private method with a default configuration for a tableView with pull to refresh. |
| Platform | All |
| Language | Swift |
| Completion Shortcut | configTable |
| Completion Scopes | ClassImplementation |#### Code
```swift
private let refreshControl = UIRefreshControl()private func configureTableView() {
tableView.delegate = self
tableView.dataSource = selflet nib = UINib(nibName: <#nibName#>, bundle: nil)
let noContentNib = UINib(nibName: <#noContentNibName#>, bundle: nil)
tableView.register(nib, forCellReuseIdentifier: <#reuseIdentifier#>)
tableView.register(noContentNib, forCellReuseIdentifier: <#noContentReuseIdentifier#>)tableView.estimatedRowHeight = <#estimatedRowHeight#>
tableView.rowHeight = UITableView.automaticDimensionif #available(iOS 10.0, *) {
tableView.refreshControl = refreshControl
} else {
tableView.addSubview(refreshControl)
}
refreshControl.addTarget(self, action: #selector(refresh(_:)), for: .valueChanged)
}@objc
private func refresh(_ sender: Any) {}
```
### TableView Delegate and DataSource
| Configuration ||
| --- | --- |
| Title | TableView Delegate and DataSource |
| Summary | Creates the extensions for tableView Delegate and DataSource with a default implementation of the most used methods. |
| Platform | All |
| Language | Swift |
| Completion Shortcut | tableDelDat |
| Completion Scopes | TopLevel |#### Code
```swift
extension <#ViewController#>: UITableViewDelegate {
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {}
}extension <#ViewController#>: UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return <#numberOfRowsInSection#>
}func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
switch indexPath.section {
case <#section#>:
return contentTableViewCell(for: indexPath)
default:
return UITableViewCell()
}
}private func contentTableViewCell(for indexPath: IndexPath) -> UITableViewCell {
if let cell = tableView.dequeueReusableCell(withIdentifier: <#cellIdentifier#>, for: indexPath) as? <#UITableViewCell#> {
cell.<#property#> = <#value#>
return cell
}
return UITableViewCell()
}private func noContentTableViewCell() -> UITableViewCell {
if let cell = tableView.dequeueReusableCell(withIdentifier: <#cellIdentifier#>) as? <#UITableViewCell#> {
cell.<#property#> = <#value#>
return cell
}
return UITableViewCell()
}
}
```
## License
Xcode Code Snippets is released under the MIT License. See [LICENSE](LICENSE.md) for details.
## Contribution
Author: [ManDon5](https://github.com/ManDon5)