❤️ Support my app ❤️
- Push Hero - pure Swift native macOS application to test push notifications
- PastePal - Pasteboard, note and shortcut manager
- Frame recorder - Recorder gif and video with frame
- Alias - App and file shortcut manager
- Other apps
❤️❤️😇😍🤘❤️❤️
A collection of Swift snippets to be used in Xcode
- swifttrycatch
do{try<#code#>}catch<#errortype#> {<#code#>}catch<#errortype#> {<#code#>}- swiftassociatedobject
privatestruct AssociatedKeys {staticvar<#name#>="<#name#>"}var<#name#>: String?{get{returnobjc_getAssociatedObject(self,&AssociatedKeys.<#name#>)as?String}set{iflet newValue = newValue {objc_setAssociatedObject(self,&AssociatedKeys.<#name#>, newValue asString?,.OBJC_ASSOCIATION_RETAIN_NONATOMIC
)}}}- swiftavailable
@available(iOS 7,*)- swiftcheckavailability
if #available(iOS 9,*){<#API available statements#>}elseif #available(macOS 10.12,*){<#API available statements#>}else{<#fallback statements#>}- swiftcheckversion
#if swift(>=3.0)<#code#>#elseif swift(>=2.2)<#code#>#elseif swift(>=2.1)<#code#>#endif- swiftcheckplatform
#if os(iOS) || os(tvOS)<#code#>#elseif os(watchOS)<#code#>#elseif os(OSX)<#code#>#endif- swiftdispatchafter
DispatchQueue.main.asyncAfter(deadline:.now()+<#time#>){<#code#>}- swiftdispatchasync
DispatchQueue.global(qos:.background).async{<#code#>}- swiftdispatchonce
let<#name#>:<#type#>={return<#code#>}()- swiftinitcoder
publicrequiredinit?(coder aDecoder:NSCoder){fatalError("init(coder:) has not been implemented")}- swiftmark
// MARK: - <#section#>- swiftsubscript
subscript(<#name#>:<#type#>)-><#type#>{get{return<#value#>}set(newValue){<#code#>}}- swiftguardself
guardlet `self` =selfelse{return}- swiftuitableviewdatasource
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
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
func numberOfComponents(in pickerView:UIPickerView)->Int{return<#count#>}func pickerView(_ pickerView:UIPickerView, numberOfRowsInComponent component:Int)->Int{return<#count#>}Drag codesnippet files from Snippets into /Library/Developer/Xcode/UserData/CodeSnippets
Run this in your terminal
curl -fsSL https://raw.githubusercontent.com/hyperoslo/SwiftSnippets/master/install.sh | sh
- Khoa Pham, onmyway133@gmai.com
- Hyper Interaktiv AS, ios@hyper.no
SwiftSnippets is available under the MIT license. See the LICENSE file for more info.