├── LICENSE ├── README.md ├── async.swift ├── cdfetch.swift ├── cvds.swift ├── documents.swift ├── dot.swift ├── frc.swift ├── imv.swift ├── mark:.swift ├── pdel.swift ├── pds.swift ├── singleton.swift ├── testf.swift ├── todo:.swift ├── tvdel.swift └── tvds.swift /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Abizer Nasir 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # xcode-snippets 2 | Swift 2 snippets for Xcode 3 | 4 | Just a few for the moment, based on those by Matt Thompson at https://github.com/Xcode-Snippets/Objective-C 5 | 6 | # Installing The Snippets 7 | 8 | ## Manually 9 | 10 | In Xcode 7, open a workspace and toggle the right sidebar to be visible. On the bottom, there is a panel with four icons in the header. Click on the `{ }` icon to open the Code Snippets Library. 11 | 12 | Now copy-paste the code from one of these snippets, highlight the code block you just pasted and drag it to the Code Snippet panel. Make sure to match the suggested platform, language, and completion scope. The completion shortcut corresponds to the filename of the code snippet. 13 | 14 | ## Using the xcodesnippet gem 15 | _by @mattt, does the guy ever sleep?_ 16 | 17 | First, install the gem `gem install xcodesnippet` 18 | 19 | Then install the snippet you want with: 20 | 21 | ``` 22 | xcodesnippet install path/to/file 23 | ``` 24 | -------------------------------------------------------------------------------- /async.swift: -------------------------------------------------------------------------------- 1 | --- 2 | title: "dispatch_async Pattern for Background Processing" 3 | summary: "Dispatch to do work in the background, and then to the main queue with the results" 4 | completion-scope: Function or Method 5 | --- 6 | 7 | dispatch_async(dispatch_get_global_queue(<#T##identifier: Int##Int#>, 0)) { [weak self] () -> Void in 8 | <#code#> 9 | 10 | dispatch_async(dispatch_get_main_queue()) { () -> Void in 11 | <#code#> 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /cdfetch.swift: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Core Data Fetch" 3 | summary: "Simple Core Data Fetch with Predicate & Sort Descriptor" 4 | completion-scope: Function or Method 5 | --- 6 | 7 | let fetchRequest = NSFetchRequest(entityName: <#T##String#>) 8 | fetchRequest.predicate = NSPredicate(format: <#T##String#>, argumentArray: <#T##[AnyObject]?#>) 9 | let sortDescriptor = NSSortDescriptor(key: <#T##String?#>, ascending: <#T##Bool#>) 10 | fetchRequest.sortDescriptors = [sortDescriptor] 11 | 12 | typealias FetchedEntity = <#Entity#> 13 | 14 | let results: [FetchedEntity] 15 | do { 16 | results = try context.executeFetchRequest(fetchRequest) as! [FetchedEntity] 17 | } catch { 18 | print(error) 19 | } 20 | -------------------------------------------------------------------------------- /cvds.swift: -------------------------------------------------------------------------------- 1 | --- 2 | title: "UICollectionViewDataSource" 3 | summary: "Placeholders for essential UICollectionViewDataSource delegate methods" 4 | platform: iOS 5 | completion-scope: Class Implementation 6 | --- 7 | 8 | extension <#Class#> : UICollectionViewDataSource { 9 | 10 | func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int { 11 | <#code#> 12 | } 13 | 14 | func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { 15 | <#code#> 16 | } 17 | 18 | func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { 19 | <#code#> 20 | } 21 | 22 | func collectionView(collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, atIndexPath indexPath: NSIndexPath) -> UICollectionReusableView { 23 | <#code#> 24 | } 25 | 26 | func collectionView(collectionView: UICollectionView, canMoveItemAtIndexPath indexPath: NSIndexPath) -> Bool { 27 | <#code#> 28 | } 29 | 30 | func collectionView(collectionView: UICollectionView, moveItemAtIndexPath sourceIndexPath: NSIndexPath, toIndexPath destinationIndexPath: NSIndexPath) { 31 | <#code#> 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /documents.swift: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Documents Directory Path" 3 | summary: "Returns the URL for the documents directory wrapped in a guard." 4 | completion-scope: Function or Method 5 | --- 6 | 7 | guard let documentsDirectoryURL = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask).first else { <#code#> } 8 | -------------------------------------------------------------------------------- /dot.swift: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Basic do-catch block" 3 | summary: "A basic do-catch block with templates for the code and error handlers" 4 | completion-scope: Function or Method 5 | --- 6 | 7 | do { 8 | <#code#> 9 | } catch { 10 | <#code#> 11 | } 12 | -------------------------------------------------------------------------------- /frc.swift: -------------------------------------------------------------------------------- 1 | --- 2 | title: "NSFetchedResultsController" 3 | summary: "Boilerplate for creating an NSFetchedResultsController" 4 | platform: iOS 5 | completion-scope: Function or Method 6 | --- 7 | 8 | let fetchRequest = NSFetchRequest(entityName: <#T##String#>) 9 | fetchRequest.predicate = NSPredicate(format: <#T##String#>, argumentArray: <#T##[AnyObject]?#>) 10 | let sortDescriptor = NSSortDescriptor(key: <#T##String?#>, ascending: <#T##Bool#>) 11 | fetchRequest.sortDescriptors = [sortDescriptor] 12 | 13 | let fetchedResultsController = NSFetchedResultsController(fetchRequest: <#T##NSFetchRequest#>, managedObjectContext: <#T##NSManagedObjectContext#>, sectionNameKeyPath: <#T##String?#>, cacheName: <#T##String?#>) 14 | fetchedResultsController.delegate = <#T##NSFetchedResultsControllerDelegate#> 15 | 16 | do { 17 | try fetchedResultsController.performFetch() 18 | } catch { 19 | <#code#> 20 | } 21 | -------------------------------------------------------------------------------- /imv.swift: -------------------------------------------------------------------------------- 1 | --- 2 | title: "ImageView" 3 | summary: "Create & Initialize UIImageView with Named Image" 4 | platform: iOS 5 | completion-scope: All 6 | --- 7 | 8 | let <#imageView#> = UIImageView(image: UIImage(named: <#T##String#>)) 9 | -------------------------------------------------------------------------------- /mark:.swift: -------------------------------------------------------------------------------- 1 | --- 2 | title: "MARK" 3 | summary: "Create a MARK: annotation" 4 | completion-scope: All 5 | --- 6 | 7 | // MARK: <#mark#> 8 | -------------------------------------------------------------------------------- /pdel.swift: -------------------------------------------------------------------------------- 1 | --- 2 | title: "UIPickerViewDelegate" 3 | summary: "Placeholders for required UIPickerView Delegate methods" 4 | platform: iOS 5 | completion-scope: Class Implementation 6 | --- 7 | 8 | extension <#Class#> : UIPickerViewDelegate { 9 | 10 | func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? { 11 | <#code#> 12 | } 13 | 14 | func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) { 15 | <#code#> 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /pds.swift: -------------------------------------------------------------------------------- 1 | --- 2 | title: "UIPickerViewDataSource" 3 | summary: "Placeholders for required UIPickerView datasource methods" 4 | platform: iOS 5 | completion-scope: Class Implementation 6 | --- 7 | 8 | extension <#Class#> : UIPickerViewDataSource { 9 | 10 | func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int { 11 | <#code#> 12 | } 13 | 14 | func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int { 15 | <#code#> 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /singleton.swift: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Shared Singleton" 3 | summary: "Definition for a singleton class" 4 | completion-scope: Class Implementation 5 | --- 6 | 7 | final class <#Singleton#> { 8 | 9 | static let sharedInstance = <#Singleton#>() 10 | 11 | private init() { 12 | <#code#> 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /testf.swift: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Basic test function." 3 | summary: "A basic test function skeleton." 4 | completion-scope: Class Implementation 5 | --- 6 | 7 | func test<#testName#>() { 8 | <#code#> 9 | } 10 | -------------------------------------------------------------------------------- /todo:.swift: -------------------------------------------------------------------------------- 1 | --- 2 | title: "TODO" 3 | summary: "Create a TODO: annotation" 4 | completion-scope: All 5 | --- 6 | 7 | // TODO: <#todo#> 8 | -------------------------------------------------------------------------------- /tvdel.swift: -------------------------------------------------------------------------------- 1 | --- 2 | title: "UITableViewDelegate" 3 | summary: "Placeholders for required UITableViewDelegate protocol methods" 4 | platform: iOS 5 | completion-scope: Class Implementation 6 | --- 7 | 8 | extension <#Class#> : UITableViewDelegate { 9 | 10 | func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { 11 | <#code#> 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /tvds.swift: -------------------------------------------------------------------------------- 1 | --- 2 | title: "UITableViewDataSource" 3 | summary: "Placeholders for required UITableViewDataSource delegate methods" 4 | platform: iOS 5 | completion-scope: Class Implementation 6 | --- 7 | 8 | extension <#Class#> : UITableViewDataSource { 9 | 10 | func numberOfSectionsInTableView(tableView: UITableView) -> Int { 11 | <#code#> 12 | } 13 | 14 | func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 15 | <#code#> 16 | } 17 | 18 | func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 19 | <#code#> 20 | } 21 | 22 | } 23 | --------------------------------------------------------------------------------