Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/onmyway133/SwiftSnippets
🍮 A collection of Swift snippets to be used in Xcode
https://github.com/onmyway133/SwiftSnippets
ios macos snippet swift
Last synced: 3 months ago
JSON representation
🍮 A collection of Swift snippets to be used in Xcode
- Host: GitHub
- URL: https://github.com/onmyway133/SwiftSnippets
- Owner: onmyway133
- License: other
- Created: 2016-07-06T21:02:23.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2020-04-14T14:03:46.000Z (over 4 years ago)
- Last Synced: 2024-07-30T10:09:29.770Z (3 months ago)
- Topics: ios, macos, snippet, swift
- Language: Shell
- Homepage:
- Size: 22.5 KB
- Stars: 163
- Watchers: 14
- Forks: 21
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
- awesome-security-collection - **135**星
- awesome-ios-star - SwiftSnippets - A collection of Swift snippets to be used in Xcode. (Reference / React-Like)
- awesome-ios - SwiftSnippets - A collection of Swift snippets to be used in Xcode. (Reference / React-Like)
README
# Swift Snippets
❤️ Support my app ❤️
- [Push Hero - pure Swift native macOS application to test push notifications](https://www.producthunt.com/posts/push-hero-2)
- [PastePal - Pasteboard, note and shortcut manager](https://www.producthunt.com/posts/pastepal)
- [Frame recorder - Recorder gif and video with frame](https://www.producthunt.com/posts/frame-recorder)
- [Alias - App and file shortcut manager](https://www.producthunt.com/posts/alias-shortcut-manager)
- [Other apps](https://onmyway133.github.io/projects/)❤️❤️😇😍🤘❤️❤️
A collection of Swift snippets to be used in Xcode
## Usage
- swifttrycatch
```swift
do {
try <#code#>
} catch <#errortype#> {
<#code#>
} catch <#errortype#> {
<#code#>
}
```- swiftassociatedobject
```swift
private struct AssociatedKeys {
static var <#name#> = "<#name#>"
}var <#name#>: String? {
get {
return objc_getAssociatedObject(self, &AssociatedKeys.<#name#>) as? String
}set {
if let newValue = newValue {
objc_setAssociatedObject(self, &AssociatedKeys.<#name#>, newValue as String?,
.OBJC_ASSOCIATION_RETAIN_NONATOMIC
)
}
}
}
```- swiftavailable
```swift
@available(iOS 7, *)
```- swiftcheckavailability
```swift
if #available(iOS 9, *) {
<#API available statements#>
} else if #available(macOS 10.12, *) {
<#API available statements#>
} else {
<#fallback statements#>
}
```- swiftcheckversion
```swift
#if swift(>=3.0)
<#code#>
#elseif swift(>=2.2)
<#code#>
#elseif swift(>=2.1)
<#code#>
#endif
```- swiftcheckplatform
```swift
#if os(iOS) || os(tvOS)
<#code#>
#elseif os(watchOS)
<#code#>
#elseif os(OSX)
<#code#>
#endif
```- swiftdispatchafter
```swift
DispatchQueue.main.asyncAfter(deadline: .now() + <#time#>) {
<#code#>
}
```- swiftdispatchasync
```swift
DispatchQueue.global(qos: .background).async {
<#code#>
}
```- swiftdispatchonce
```swift
let <#name#>: <#type#> = {
return <#code#>
}()
```- swiftinitcoder
```swift
public required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
```- swiftmark
```swift
// MARK: - <#section#>
```- swiftsubscript
```swift
subscript(<#name#>: <#type#>) -> <#type#> {
get {
return <#value#>
}
set(newValue) {
<#code#>
}
}
```- swiftguardself
```swift
guard let `self` = self else {
return
}
```- swiftuitableviewdatasource
```swift
func numberOfSections(in tableView: UITableView) -> Int {
return <#count#>
}func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return <#count#>
}func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
<#code#>
}
```- swiftuicollectionviewdatasource
```swift
func numberOfSections(in collectionView: UICollectionView) -> Int {
return <#count#>
}func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return <#count#>
}func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
<#code#>
}
```- swiftuipickerviewdatasource
```swift
func numberOfComponents(in pickerView: UIPickerView) -> Int {
return <#count#>
}func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return <#count#>
}
```## Installation
### Manual
Drag `codesnippet` files from `Snippets` into `/Library/Developer/Xcode/UserData/CodeSnippets`
### Automatic
Run this in your terminal
```
curl -fsSL https://raw.githubusercontent.com/hyperoslo/SwiftSnippets/master/install.sh | sh
```## Author
- Khoa Pham, [email protected]
## Credit
- Hyper Interaktiv AS, [email protected]
## License
**SwiftSnippets** is available under the MIT license. See the LICENSE file for more info.