├── LICENSE
├── Readme.md
├── assets
├── .DS_Store
├── create.gif
├── create.mov
├── create_gif.sh
├── elegant-mark.png
├── use.gif
└── use.mov
├── generate_list.py
├── swift-closureoptionaltypealias.codesnippet
├── swift-closuretypealias.codesnippet
├── swift-createproperty.codesnippet
├── swift-didbecomeactive.codesnippet
├── swift-dispatchafter.codesnippet
├── swift-dispatchasync.codesnippet
├── swift-dispatchmain.codesnippet
├── swift-documentdirectory.codesnippet
├── swift-elegantmark.codesnippet
├── swift-forin.codesnippet
├── swift-ibaction.codesnippet
├── swift-iboutlet.codesnippet
├── swift-mail.codesnippet
├── swift-mark.codesnippet
├── swift-message.codesnippet
├── swift-nslocalizedstring.codesnippet
├── swift-singleton.codesnippet
├── swift-sortarrayofstrings.codesnippet
├── swift-uialertcontroller.codesnippet
├── swift-uiapplicationdelegate.codesnippet
├── swift-uicollectionviewdatasource.codesnippet
├── swift-uicollectionviewdelegate.codesnippet
├── swift-uiremotenotification.codesnippet
├── swift-uitableviewdatasource.codesnippet
├── swift-uitableviewdelegate.codesnippet
├── swift-uiviewcontrollerlifecycle.codesnippet
├── swift-urlsession-datatask.codesnippet
├── swift-urlsession-delegate.codesnippet
└── swift-weak.codesnippet
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2015 Kamil Burczyk
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 Swift Code Snippets
2 |
3 | I want to present some convenient code snippets I gathered for [Swift](https://developer.apple.com/swift/).
4 |
5 | ### All snippets are updated to **Swift 4** ❤️
6 |
7 | ## Inspiration
8 | I was inspired by Matt Thompson's [Xcode-Snippets](https://github.com/mattt/Xcode-Snippets) article and GitHub repo but I haven't found anything similar for Swift.
9 |
10 | I also used [that thing in swift](https://thatthinginswift.com) and [SwiftSingleton](https://github.com/hpique/SwiftSingleton) as a sample implementations.
11 |
12 | ## How to import all code snippets to Xcode
13 | All Xcode code snippets exist as a `.plist` files in `~/Library/Developer/Xcode/UserData/CodeSnippets/`
14 | You can simply copy all code snippets (`.codesnippet`) into this folder, restart Xcode and you should have all of them ready to use.
15 |
16 | Note: Create the folder if it doesn't exist already. It is created by Xcode when user adds his first custom snippet.
17 |
18 | ## Usage
19 | I named all snippets using scheme `Swift ...` and set all Completion Shortcuts to `swift-...` so each time you type `swift` in code editor you should see all snippets you can use in that place.
20 |
21 | 
22 |
23 | ## How to create your own snippets
24 | To add code snippet to Xcode expand **Utilities** right panel and press `{}` button (*Show the Code Snippet library*) in lower panel.
25 | Then select a code you would like to treat as a snippet, press and hold a left mouse button for a while and drag whole selection to the right panel (if you drag too early you'll probably only deselect text; you can also try dragging from a whitespace instead of the letter).
26 |
27 | 
28 |
29 | ### Placeholder tokens
30 | If you want to add this nice placeholder in rounded blue rect simply put it between `<#` and `#>` and it will be transformed in both editor and final snippet.
31 |
32 | ## Snippets
33 | Currently existing snippets (I hope they will be updated on a regular basis with your help :) ):
34 |
35 | ```
36 | swift-documentdirectory Document directory path snippet for Swift
37 | swift-dispatchafter GCD dispatch_after snippet for Swift
38 |
39 | swift-dispatchasync GCD dispatch_async snippet for Swift
40 | swift-nslocalizedstring NSLocalizedString function snippet for Swift
41 | swift-dispatchmain GCD dispatch_async on main queue snippet for Swift
42 | swift-closuretypealias Closure typealias with arguments and return value snippet for Swift
43 | swift-weak weakify self in closure
44 | swift-uitableviewdelegate UITableViewDelegate snippet for Swift
45 | swift-forin for-in loop that casts objects inline
46 | swift-ibo Stub out IBOutlet
47 | swift-sortarrayofstrings Swift String Array locale-aware sorting
48 | swift-prop Auto-Create property stub
49 | swift-closureoptionaltypealias Optional closure typealiast with arguments and return value snippet for Swift
50 | swift-urlsession-delegate Swift HTTP Request With Delegate set
51 | swift-message MFMessageComposeViewController snippet for Swift
52 | swift-uiviewcontrollerlifecycle UIViewController lifecycle snippet for Swift
53 | swift-uicollectionviewdelegate UICollectionViewDelegate snippet for Swift
54 | swift-uiremotenotification UIRemoteNotification registration and handling snippet for Swift
55 | swift-mark Divider label for separating code into sections
56 | swift-didbecomeactive UIApplicationDidBecomeActiveNotification observer snippet for Swift
57 | swift-urlsession-datatask Swift Simple HTTP Request
58 | swift-mail MFMailComposeViewController snippet for Swift
59 | swift-iba Create IBAction method stub
60 | swift-uicollectionviewdatasource UICollectionViewDataSource snippet for Swift
61 | swift-singleton Singleton pattern for Swift
62 | swift-uitableviewdatasource UITableViewDataSource snippet for Swift
63 | swift-uiapplicationdelegate Commonly used app life cycle methods
64 | swift-elegantmark Decorates mark statements and makes it neat when looking through items in File Jump Bar
65 | ```
66 |
67 |
68 | ## More snippets?
69 | This is a good start but I encourage you to create your own snippets or correct existing ones and create Pull Requests. Please provide plain snippets as `.plist` files so they can be easily imported.
70 | You can use `plist/generate_list.py` script to generate snippets list by running: `python generate_list.py`.
71 |
72 | ## Do you like it?
73 | Do you like this repo? Share it on Twitter, Facebook, Google+ or anywhere you like so that more of us can use it and help. Thanks!
74 |
--------------------------------------------------------------------------------
/assets/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/burczyk/XcodeSwiftSnippets/9524157923696b7a819f37824684ab7d05cd84a5/assets/.DS_Store
--------------------------------------------------------------------------------
/assets/create.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/burczyk/XcodeSwiftSnippets/9524157923696b7a819f37824684ab7d05cd84a5/assets/create.gif
--------------------------------------------------------------------------------
/assets/create.mov:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/burczyk/XcodeSwiftSnippets/9524157923696b7a819f37824684ab7d05cd84a5/assets/create.mov
--------------------------------------------------------------------------------
/assets/create_gif.sh:
--------------------------------------------------------------------------------
1 | ffmpeg -i xcode-use-code-snippet.mov -vf scale=434:-1 -r 10 -f image2pipe -vcodec ppm - | convert -delay 5 -loop 0 - xcode-use-code-snippet.gif
2 | #http://superuser.com/questions/556029/how-do-i-convert-a-video-to-gif-using-ffmpeg-with-reasonable-quality
--------------------------------------------------------------------------------
/assets/elegant-mark.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/burczyk/XcodeSwiftSnippets/9524157923696b7a819f37824684ab7d05cd84a5/assets/elegant-mark.png
--------------------------------------------------------------------------------
/assets/use.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/burczyk/XcodeSwiftSnippets/9524157923696b7a819f37824684ab7d05cd84a5/assets/use.gif
--------------------------------------------------------------------------------
/assets/use.mov:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/burczyk/XcodeSwiftSnippets/9524157923696b7a819f37824684ab7d05cd84a5/assets/use.mov
--------------------------------------------------------------------------------
/generate_list.py:
--------------------------------------------------------------------------------
1 | import os
2 | from xml.dom import minidom
3 |
4 | for root, dirs, files in os.walk("."):
5 | for file in files:
6 | if file.endswith('.codesnippet'):
7 | xmldoc = minidom.parse(file)
8 | keys = xmldoc.getElementsByTagName('dict')[0].getElementsByTagName('key')
9 | summary = ""
10 | prefix = ""
11 | file_short = file[:file.find('-')]
12 | for key in keys:
13 | if key.firstChild.nodeValue == 'IDECodeSnippetSummary':
14 | summary = key.nextSibling.nextSibling.firstChild.nodeValue
15 | elif key.firstChild.nodeValue == 'IDECodeSnippetCompletionPrefix':
16 | prefix = key.nextSibling.nextSibling.firstChild.nodeValue
17 | # print "[%s] %s" % (prefix, summary)
18 | print '{0: <36} {1}'.format(prefix, summary)
--------------------------------------------------------------------------------
/swift-closureoptionaltypealias.codesnippet:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDECodeSnippetCompletionPrefix
6 | swift-closureoptionaltypealias
7 | IDECodeSnippetCompletionScopes
8 |
9 | ClassImplementation
10 |
11 | IDECodeSnippetContents
12 | typealias <#ClosureName#> = ((_ <#arguments#>: <#type#>) -> <#return value#>)?
13 | IDECodeSnippetIdentifier
14 | 1528A53D-69CA-4A12-908A-1F85A47A8644
15 | IDECodeSnippetLanguage
16 | Xcode.SourceCodeLanguage.Swift
17 | IDECodeSnippetSummary
18 | Optional closure typealiast with arguments and return value snippet for Swift
19 | IDECodeSnippetTitle
20 | Swift optional closure typealias
21 | IDECodeSnippetUserSnippet
22 |
23 | IDECodeSnippetVersion
24 | 2
25 |
26 |
27 |
--------------------------------------------------------------------------------
/swift-closuretypealias.codesnippet:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDECodeSnippetCompletionPrefix
6 | swift-closuretypealias
7 | IDECodeSnippetCompletionScopes
8 |
9 | ClassImplementation
10 |
11 | IDECodeSnippetContents
12 | typealias <#ClosureName#> = (_ <#arguments#>: <#type#>) -> <#return value#>
13 | IDECodeSnippetIdentifier
14 | 42AA2BDB-AA64-4260-9726-A72C20E79FBB
15 | IDECodeSnippetLanguage
16 | Xcode.SourceCodeLanguage.Swift
17 | IDECodeSnippetSummary
18 | Closure typealias with arguments and return value snippet for Swift
19 | IDECodeSnippetTitle
20 | Swift closure typealias
21 | IDECodeSnippetUserSnippet
22 |
23 | IDECodeSnippetVersion
24 | 2
25 |
26 |
27 |
--------------------------------------------------------------------------------
/swift-createproperty.codesnippet:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDECodeSnippetCompletionPrefix
6 | swift-prop
7 | IDECodeSnippetCompletionScopes
8 |
9 | ClassImplementation
10 |
11 | IDECodeSnippetContents
12 | var <# name #> : <# type #> {
13 | get { return <# varName #> }
14 | set { <# varName #> = value }
15 | }
16 | IDECodeSnippetIdentifier
17 | 3759C0E1-EAE1-4321-88CD-54F1EEF38E90
18 | IDECodeSnippetLanguage
19 | Xcode.SourceCodeLanguage.Swift
20 | IDECodeSnippetTitle
21 | IDECodeSnippetSummary
22 | Auto-Create property stub
23 | AutoProperty
24 | IDECodeSnippetUserSnippet
25 |
26 | IDECodeSnippetVersion
27 | 2
28 |
29 |
30 |
--------------------------------------------------------------------------------
/swift-didbecomeactive.codesnippet:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDECodeSnippetCompletionPrefix
6 | swift-didbecomeactive
7 | IDECodeSnippetCompletionScopes
8 |
9 | CodeBlock
10 |
11 | IDECodeSnippetContents
12 | NotificationCenter.default.addObserver(self, selector: #selector(<#selector#>), name: NSNotification.Name.UIApplicationDidBecomeActive, object: nil)
13 | IDECodeSnippetIdentifier
14 | DA8B025D-2EEA-4917-98FA-6ED8DCA1ED2B
15 | IDECodeSnippetLanguage
16 | Xcode.SourceCodeLanguage.Swift
17 | IDECodeSnippetSummary
18 | UIApplicationDidBecomeActiveNotification observer snippet for Swift
19 | IDECodeSnippetTitle
20 | Swift add DidBecomeActive notification observer
21 | IDECodeSnippetUserSnippet
22 |
23 | IDECodeSnippetVersion
24 | 2
25 |
26 |
27 |
--------------------------------------------------------------------------------
/swift-dispatchafter.codesnippet:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDECodeSnippetCompletionPrefix
6 | swift-dispatchafter
7 | IDECodeSnippetCompletionScopes
8 |
9 | CodeBlock
10 |
11 | IDECodeSnippetContents
12 | DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(<#seconds#>)) {
13 |
14 | }
15 | IDECodeSnippetIdentifier
16 | E772ABB6-7616-42C2-9F95-9884388957EE
17 | IDECodeSnippetLanguage
18 | Xcode.SourceCodeLanguage.Swift
19 | IDECodeSnippetSummary
20 | GCD dispatch_after snippet for Swift
21 | IDECodeSnippetTitle
22 | Swift dispatch_after
23 | IDECodeSnippetUserSnippet
24 |
25 | IDECodeSnippetVersion
26 | 2
27 |
28 |
29 |
--------------------------------------------------------------------------------
/swift-dispatchasync.codesnippet:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDECodeSnippetCompletionPrefix
6 | swift-dispatchasync
7 | IDECodeSnippetCompletionScopes
8 |
9 | CodeBlock
10 |
11 | IDECodeSnippetContents
12 | DispatchQueue.global(qos: .default).async {
13 | <#asynchronous work#>
14 | DispatchQueue.main.async {
15 | <#callback#>
16 | }
17 | }
18 | IDECodeSnippetIdentifier
19 | 731C3867-9874-4559-8350-5F2B054A5AF9
20 | IDECodeSnippetLanguage
21 | Xcode.SourceCodeLanguage.Swift
22 | IDECodeSnippetSummary
23 | GCD dispatch_async snippet for Swift
24 | IDECodeSnippetTitle
25 | Swift dispatch_async
26 | IDECodeSnippetUserSnippet
27 |
28 | IDECodeSnippetVersion
29 | 2
30 |
31 |
32 |
--------------------------------------------------------------------------------
/swift-dispatchmain.codesnippet:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDECodeSnippetCompletionPrefix
6 | swift-dispatchmain
7 | IDECodeSnippetCompletionScopes
8 |
9 | CodeBlock
10 |
11 | IDECodeSnippetContents
12 | DispatchQueue.main.async(execute: { () -> Void in
13 |
14 | })
15 | IDECodeSnippetIdentifier
16 | E8847AF3-D9A6-40C6-9DC1-981DD1A1042A
17 | IDECodeSnippetLanguage
18 | Xcode.SourceCodeLanguage.Swift
19 | IDECodeSnippetSummary
20 | GCD dispatch_async on main queue snippet for Swift
21 | IDECodeSnippetTitle
22 | Swift dispatch_async on main queue
23 | IDECodeSnippetUserSnippet
24 |
25 | IDECodeSnippetVersion
26 | 2
27 |
28 |
29 |
--------------------------------------------------------------------------------
/swift-documentdirectory.codesnippet:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDECodeSnippetCompletionPrefix
6 | swift-documentdirectory
7 | IDECodeSnippetCompletionScopes
8 |
9 | CodeBlock
10 |
11 | IDECodeSnippetContents
12 | if let path = NSSearchPathForDirectoriesInDomains(FileManager.SearchPathDirectory.documentDirectory, FileManager.SearchPathDomainMask.userDomainMask, true).first {
13 | let documentsDirectoryURL = NSURL.fileURL(withPath: path)
14 | }
15 | IDECodeSnippetIdentifier
16 | E3AE2218-F56E-45BE-909F-1EC5DE83F3AE
17 | IDECodeSnippetLanguage
18 | Xcode.SourceCodeLanguage.Swift
19 | IDECodeSnippetSummary
20 | Document directory path snippet for Swift
21 | IDECodeSnippetTitle
22 | Swift document directory
23 | IDECodeSnippetUserSnippet
24 |
25 | IDECodeSnippetVersion
26 | 2
27 |
28 |
29 |
--------------------------------------------------------------------------------
/swift-elegantmark.codesnippet:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDECodeSnippetCompletionPrefix
6 | swift-elegantmark
7 | IDECodeSnippetCompletionScopes
8 |
9 | All
10 |
11 | IDECodeSnippetContents
12 |
13 | ////////////////////////////////////////////////////////////////
14 | //MARK:-
15 | //MARK:<#Section#>
16 | //MARK:-
17 | ////////////////////////////////////////////////////////////////
18 |
19 | IDECodeSnippetIdentifier
20 | 76C4B4B4-1F7D-41D8-9CE2-0E4E36C668D0
21 | IDECodeSnippetLanguage
22 | Xcode.SourceCodeLanguage.Generic
23 | IDECodeSnippetSummary
24 | Decorates mark statements and makes it neat when looking through items in File Jump Bar
25 | IDECodeSnippetTitle
26 | Elegant Mark
27 | IDECodeSnippetUserSnippet
28 |
29 | IDECodeSnippetVersion
30 | 2
31 |
32 |
33 |
--------------------------------------------------------------------------------
/swift-forin.codesnippet:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDECodeSnippetCompletionPrefix
6 | swift-forin
7 | IDECodeSnippetCompletionScopes
8 |
9 | CodeBlock
10 |
11 | IDECodeSnippetContents
12 | for case let <#object#> in <#collection#> as [<#Type#>] {
13 |
14 | }
15 | IDECodeSnippetIdentifier
16 | 48C9EB7D-A166-4781-8DC8-6961B57BDC02
17 | IDECodeSnippetLanguage
18 | Xcode.SourceCodeLanguage.Swift
19 | IDECodeSnippetSummary
20 | for-in loop that casts objects inline
21 | IDECodeSnippetTitle
22 | Swift for-in loop with casting
23 | IDECodeSnippetUserSnippet
24 |
25 | IDECodeSnippetVersion
26 | 2
27 |
28 |
29 |
--------------------------------------------------------------------------------
/swift-ibaction.codesnippet:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDECodeSnippetCompletionPrefix
6 | swift-iba
7 | IDECodeSnippetCompletionScopes
8 |
9 | ClassImplementation
10 |
11 | IDECodeSnippetContents
12 | @IBAction func <# FuncName #>(_ sender: AnyObject) {
13 | <# code #>
14 | }
15 | IDECodeSnippetIdentifier
16 | A913F681-E983-4127-B303-EDAC5EDD48AA
17 | IDECodeSnippetLanguage
18 | Xcode.SourceCodeLanguage.Swift
19 | IDECodeSnippetSummary
20 | Create IBAction method stub
21 | IDECodeSnippetTitle
22 | IBAction
23 | IDECodeSnippetUserSnippet
24 |
25 | IDECodeSnippetVersion
26 | 2
27 |
28 |
29 |
--------------------------------------------------------------------------------
/swift-iboutlet.codesnippet:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDECodeSnippetCompletionPrefix
6 | swift-ibo
7 | IDECodeSnippetCompletionScopes
8 |
9 | ClassImplementation
10 |
11 | IDECodeSnippetContents
12 | @IBOutlet weak var <# OutletName #>: <# OutletType #>!
13 | IDECodeSnippetIdentifier
14 | F0FAF3C5-71F4-4009-B09B-15FB3AE62C60
15 | IDECodeSnippetLanguage
16 | Xcode.SourceCodeLanguage.Swift
17 | IDECodeSnippetSummary
18 | Stub out IBOutlet
19 | IDECodeSnippetTitle
20 | IBOutlet
21 | IDECodeSnippetUserSnippet
22 |
23 | IDECodeSnippetVersion
24 | 2
25 |
26 |
27 |
--------------------------------------------------------------------------------
/swift-mail.codesnippet:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDECodeSnippetCompletionPrefix
6 | swift-mail
7 | IDECodeSnippetCompletionScopes
8 |
9 | ClassImplementation
10 |
11 | IDECodeSnippetContents
12 | //MARK: MFMailComposeViewController
13 |
14 | func presentModalMailComposerViewController(animated: Bool) {
15 | if MFMailComposeViewController.canSendMail() {
16 | let mailComposeVC = MFMailComposeViewController()
17 | mailComposeVC.delegate = <#delegate#>
18 |
19 | mailComposeVC.setSubject(<#subject#>)
20 | mailComposeVC.setMessageBody(<#body#>, isHTML: true)
21 | mailComposeVC.setToRecipients([<#recipients#>])
22 |
23 | present(mailComposeVC, animated: animated, completion: nil)
24 | } else {
25 | let alert = UIAlertController(title: NSLocalizedString("Error", value: "Error", comment: ""),
26 | message: NSLocalizedString("Your device doesn't support Mail messaging", value: "Your device doesn't support Mail messaging", comment: ""),
27 | preferredStyle: .alert)
28 | alert.addAction(UIAlertAction(title: NSLocalizedString("Cancel", comment: "Cancel"), style: .cancel, handler: nil))
29 | present(alert, animated: true, completion: nil)
30 | }
31 | }
32 |
33 | //MARK: MFMailComposeViewControllerDelegate
34 |
35 | func mailComposeController(controller: MFMailComposeViewController!, didFinishWithResult result: MFMailComposeResult, error: NSError!) {
36 |
37 | if error != nil {
38 | print("Error: \(error)")
39 | }
40 |
41 | dismiss(animated: true)
42 | }
43 | IDECodeSnippetIdentifier
44 | 449FB7DE-54FE-4AFA-94AB-F7401AB5A5C8
45 | IDECodeSnippetLanguage
46 | Xcode.SourceCodeLanguage.Swift
47 | IDECodeSnippetSummary
48 | MFMailComposeViewController snippet for Swift
49 | IDECodeSnippetTitle
50 | Swift MFMailComposeViewController
51 | IDECodeSnippetUserSnippet
52 |
53 | IDECodeSnippetVersion
54 | 2
55 |
56 |
57 |
--------------------------------------------------------------------------------
/swift-mark.codesnippet:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDECodeSnippetCompletionPrefix
6 | swift-mark
7 | IDECodeSnippetCompletionScopes
8 |
9 | TopLevel
10 | ClassImplementation
11 |
12 | IDECodeSnippetContents
13 | // MARK: - <#Section#>
14 | IDECodeSnippetIdentifier
15 | 7329708D-DA17-4129-A8F9-A780DFA5FAE1
16 | IDECodeSnippetLanguage
17 | Xcode.SourceCodeLanguage.Swift
18 | IDECodeSnippetSummary
19 | Divider label for separating code into sections
20 | IDECodeSnippetTitle
21 | Swift Mark:
22 | IDECodeSnippetUserSnippet
23 |
24 | IDECodeSnippetVersion
25 | 2
26 |
27 |
28 |
--------------------------------------------------------------------------------
/swift-message.codesnippet:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDECodeSnippetCompletionPrefix
6 | swift-message
7 | IDECodeSnippetCompletionScopes
8 |
9 | ClassImplementation
10 |
11 | IDECodeSnippetContents
12 | //MARK: MFMessageComposeViewController
13 |
14 | func presentModalMessageComposeViewController(animated: Bool) {
15 | if MFMessageComposeViewController.canSendText() {
16 | let messageComposeVC = MFMessageComposeViewController()
17 |
18 | messageComposeVC.messageComposeDelegate = <#delegate#>
19 | messageComposeVC.body = "<#body#>"
20 | messageComposeVC.recipients = [<#recipients#>]
21 |
22 | present(messageComposeVC, animated: animated, completion: nil)
23 |
24 | } else {
25 | let alert = UIAlertController(title: NSLocalizedString("Error", value: "Error", comment: ""),
26 | message: NSLocalizedString("Your device doesn't support messaging", value: "Your device doesn't support messaging", comment: ""),
27 | preferredStyle: .alert)
28 | alert.addAction(UIAlertAction(title: NSLocalizedString("Cancel", comment: "Cancel"), style: .cancel, handler: nil))
29 | present(alert, animated: true, completion: nil)
30 | }
31 | }
32 |
33 | func messageComposeViewController(controller: MFMessageComposeViewController!, didFinishWithResult result: MessageComposeResult) {
34 | dismiss(animated: true)
35 | }
36 | IDECodeSnippetIdentifier
37 | 3165F25A-E44B-4165-A15B-F04A47A0853D
38 | IDECodeSnippetLanguage
39 | Xcode.SourceCodeLanguage.Swift
40 | IDECodeSnippetSummary
41 | MFMessageComposeViewController snippet for Swift
42 | IDECodeSnippetTitle
43 | Swift MFMessageComposeViewController
44 | IDECodeSnippetUserSnippet
45 |
46 | IDECodeSnippetVersion
47 | 2
48 |
49 |
50 |
--------------------------------------------------------------------------------
/swift-nslocalizedstring.codesnippet:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDECodeSnippetCompletionPrefix
6 | swift-nslocalizedstring
7 | IDECodeSnippetCompletionScopes
8 |
9 | All
10 |
11 | IDECodeSnippetContents
12 | NSLocalizedString(<#key#>, comment: <#comment#>)
13 | IDECodeSnippetIdentifier
14 | F60D36B3-5FE0-4C44-92AD-E33658E5AF89
15 | IDECodeSnippetLanguage
16 | Xcode.SourceCodeLanguage.Swift
17 | IDECodeSnippetSummary
18 | NSLocalizedString function snippet for Swift
19 | IDECodeSnippetTitle
20 | Swift NSLocalizedString
21 | IDECodeSnippetUserSnippet
22 |
23 | IDECodeSnippetVersion
24 | 2
25 |
26 |
27 |
--------------------------------------------------------------------------------
/swift-singleton.codesnippet:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDECodeSnippetCompletionPrefix
6 | swift-singleton
7 | IDECodeSnippetCompletionScopes
8 |
9 | ClassImplementation
10 |
11 | IDECodeSnippetContents
12 | static let shared : <#SingletonClass#> = <#SingletonClass#>()
13 | IDECodeSnippetIdentifier
14 | D0964789-8FAA-4A94-8E5B-D5178137F102
15 | IDECodeSnippetLanguage
16 | Xcode.SourceCodeLanguage.Swift
17 | IDECodeSnippetSummary
18 | Singleton pattern for Swift
19 | IDECodeSnippetTitle
20 | Swift Singleton
21 | IDECodeSnippetUserSnippet
22 |
23 | IDECodeSnippetVersion
24 | 2
25 |
26 |
27 |
--------------------------------------------------------------------------------
/swift-sortarrayofstrings.codesnippet:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDECodeSnippetCompletionPrefix
6 | swift-sortarrayofstrings
7 | IDECodeSnippetCompletionScopes
8 |
9 | CodeBlock
10 |
11 | IDECodeSnippetContents
12 | <#arrayOfStrings#>.sorted { (a, b) -> Bool in
13 | let comparisonResult = a.compare(b, options: [], range: a.range(of: a), locale: Locale.current)
14 | return comparisonResult == .orderedSame
15 | }
16 | IDECodeSnippetIdentifier
17 | B005E7A7-789D-43C2-873A-0DD8040EE2B8
18 | IDECodeSnippetLanguage
19 | Xcode.SourceCodeLanguage.Swift
20 | IDECodeSnippetSummary
21 | Swift String Array locale-aware sorting
22 | IDECodeSnippetTitle
23 | Swift String Array locale-aware sorting
24 | IDECodeSnippetUserSnippet
25 |
26 | IDECodeSnippetVersion
27 | 2
28 |
29 |
30 |
--------------------------------------------------------------------------------
/swift-uialertcontroller.codesnippet:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDECodeSnippetCompletionPrefix
6 | swift-uialertcontroller
7 | IDECodeSnippetCompletionScopes
8 |
9 | CodeBlock
10 |
11 | IDECodeSnippetContents
12 | let alert = UIAlertController(title: <#title#>, message: <#message#>, preferredStyle: .alert)
13 | alert.addAction(UIAlertAction(title: "", style: .default, handler: { (action) in
14 | alert.dismiss(animated: <#Bool#>, completion: {
15 | <#code#>
16 | })
17 | }))
18 |
19 | presentViewController(alert, animated: true, completion: nil)
20 | IDECodeSnippetIdentifier
21 | 3141D76F-5123-4B60-8D39-8AD76BF37BF4
22 | IDECodeSnippetLanguage
23 | Xcode.SourceCodeLanguage.Swift
24 | IDECodeSnippetSummary
25 | Present a UIAlertController
26 | IDECodeSnippetTitle
27 | Swift - UIAlertController
28 | IDECodeSnippetUserSnippet
29 |
30 | IDECodeSnippetVersion
31 | 2
32 |
33 |
34 |
--------------------------------------------------------------------------------
/swift-uiapplicationdelegate.codesnippet:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDECodeSnippetCompletionPrefix
6 | swift-uiapplicationdelegate
7 | IDECodeSnippetCompletionScopes
8 |
9 | ClassImplementation
10 |
11 | IDECodeSnippetContents
12 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
13 |
14 | return true
15 | }
16 |
17 | func applicationWillResignActive(_ application: UIApplication) {
18 |
19 | }
20 |
21 | func applicationDidBecomeActive(_ application: UIApplication) {
22 |
23 | }
24 |
25 | func applicationWillEnterForeground(_ application: UIApplication) {
26 |
27 | }
28 |
29 | func applicationDidEnterBackground(_ application: UIApplication) {
30 |
31 | }
32 |
33 | func applicationWillTerminate(_ application: UIApplication) {
34 |
35 | }
36 | IDECodeSnippetIdentifier
37 | CB10B10E-410C-4668-8B94-4322438AE77B
38 | IDECodeSnippetLanguage
39 | Xcode.SourceCodeLanguage.Swift
40 | IDECodeSnippetSummary
41 | Commonly used app life cycle methods
42 | IDECodeSnippetTitle
43 | Swift - UIApplication Delegate methods
44 | IDECodeSnippetUserSnippet
45 |
46 | IDECodeSnippetVersion
47 | 0
48 |
49 |
50 |
--------------------------------------------------------------------------------
/swift-uicollectionviewdatasource.codesnippet:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDECodeSnippetCompletionPrefix
6 | swift-uicollectionviewdatasource
7 | IDECodeSnippetCompletionScopes
8 |
9 | ClassImplementation
10 |
11 | IDECodeSnippetContents
12 | //MARK: UICollectionViewDataSource
13 |
14 | func numberOfSections(in collectionView: UICollectionView) -> Int {
15 | return <#numberOfSections#>
16 | }
17 |
18 | func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
19 | // TODO:- Required Method
20 | return <#numberOfItems#>
21 | }
22 |
23 | func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
24 | let cell = collectionView.dequeueReusableCell(withReuseIdentifier: <#identifier#>, for: indexPath)
25 | configureCell(cell: cell, forItemAt: indexPath)
26 | // TODO:- Required Method
27 | return cell
28 | }
29 |
30 | func configureCell(cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
31 |
32 | }
33 |
34 | func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
35 | let view = collectionView.dequeueReusableSupplementaryView(ofKind: UICollectionElementKindSectionHeader, withReuseIdentifier: <#identifier#>, for: indexPath)
36 | return view
37 | }
38 | IDECodeSnippetIdentifier
39 | 5871FA36-D43A-4505-897B-B2D54B4C611B
40 | IDECodeSnippetLanguage
41 | Xcode.SourceCodeLanguage.Swift
42 | IDECodeSnippetSummary
43 | UICollectionViewDataSource snippet for Swift
44 | IDECodeSnippetTitle
45 | Swift UICollectionViewDataSource
46 | IDECodeSnippetUserSnippet
47 |
48 | IDECodeSnippetVersion
49 | 2
50 |
51 |
52 |
--------------------------------------------------------------------------------
/swift-uicollectionviewdelegate.codesnippet:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDECodeSnippetCompletionPrefix
6 | swift-uicollectionviewdelegate
7 | IDECodeSnippetCompletionScopes
8 |
9 | ClassImplementation
10 |
11 | IDECodeSnippetContents
12 | //MARK: UICollectionViewDelegate
13 |
14 | func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
15 |
16 | }
17 |
18 | func collectionView(_ collectionView: UICollectionView, didDeselectItemAt indexPath: IndexPath) {
19 |
20 | }
21 | IDECodeSnippetIdentifier
22 | 695424DE-F323-475A-AC77-2010DDA924BB
23 | IDECodeSnippetLanguage
24 | Xcode.SourceCodeLanguage.Swift
25 | IDECodeSnippetSummary
26 | UICollectionViewDelegate snippet for Swift
27 | IDECodeSnippetTitle
28 | Swift UICollectionViewDelegate
29 | IDECodeSnippetUserSnippet
30 |
31 | IDECodeSnippetVersion
32 | 2
33 |
34 |
35 |
--------------------------------------------------------------------------------
/swift-uiremotenotification.codesnippet:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDECodeSnippetCompletionPrefix
6 | swift-uiremotenotification
7 | IDECodeSnippetCompletionScopes
8 |
9 | ClassImplementation
10 |
11 | IDECodeSnippetContents
12 | //MARK: Remote Notifications
13 |
14 | // Move this line somewhere where your app starts
15 | // UIApplication.shared.registerForRemoteNotifications()
16 |
17 | // Ask user for allowed notification types
18 | // let settings = UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
19 | // UIApplication.shared.registerUserNotificationSettings(settings)
20 |
21 | func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
22 | print("Successfully egistered for Remote Notifications with token: \(deviceToken)")
23 | }
24 |
25 | func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
26 | print("Registration for Remote Notifications failed with error: \(error)")
27 | }
28 |
29 | func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any]) {
30 |
31 | }
32 | IDECodeSnippetIdentifier
33 | 0ADC5D4B-64A3-42B1-8A4D-5741D99D0714
34 | IDECodeSnippetLanguage
35 | Xcode.SourceCodeLanguage.Swift
36 | IDECodeSnippetSummary
37 | UIRemoteNotification registration and handling snippet for Swift
38 | IDECodeSnippetTitle
39 | Swift UIRemoteNotification
40 | IDECodeSnippetUserSnippet
41 |
42 | IDECodeSnippetVersion
43 | 2
44 |
45 |
46 |
--------------------------------------------------------------------------------
/swift-uitableviewdatasource.codesnippet:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDECodeSnippetCompletionPrefix
6 | swift-uitableviewdatasource
7 | IDECodeSnippetCompletionScopes
8 |
9 | ClassImplementation
10 |
11 | IDECodeSnippetContents
12 | //MARK: UITableViewDataSource
13 |
14 | func numberOfSections(in tableView: UITableView) -> Int {
15 | return <#numberOfSections#>
16 | }
17 |
18 | func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
19 | return <#numberOfRows#>
20 | }
21 |
22 | func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
23 | let cell = tableView.dequeueReusableCell(withIdentifier: <#identifier#>, for: indexPath)
24 | configureCell(cell: cell, forRowAt: indexPath)
25 | return cell
26 | }
27 |
28 | func configureCell(cell: UITableViewCell, forRowAt indexPath: IndexPath) {
29 |
30 | }
31 | IDECodeSnippetIdentifier
32 | 380DBCD1-ECFB-4A8C-B7B2-DDE628A540E3
33 | IDECodeSnippetLanguage
34 | Xcode.SourceCodeLanguage.Swift
35 | IDECodeSnippetSummary
36 | UITableViewDataSource snippet for Swift
37 | IDECodeSnippetTitle
38 | Swift UITableViewDataSource
39 | IDECodeSnippetUserSnippet
40 |
41 | IDECodeSnippetVersion
42 | 2
43 |
44 |
45 |
--------------------------------------------------------------------------------
/swift-uitableviewdelegate.codesnippet:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDECodeSnippetCompletionPrefix
6 | swift-uitableviewdelegate
7 | IDECodeSnippetCompletionScopes
8 |
9 | ClassImplementation
10 |
11 | IDECodeSnippetContents
12 | //MARK: UITableViewDelegate
13 |
14 | func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
15 |
16 | }
17 |
18 | func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
19 |
20 | }
21 |
22 | func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
23 |
24 | }
25 |
26 | func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
27 |
28 | }
29 |
30 | func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
31 |
32 | }
33 |
34 | func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
35 |
36 | }
37 | IDECodeSnippetIdentifier
38 | 183B54E8-CAE0-4C8F-B8B3-43E3965FDF1A
39 | IDECodeSnippetLanguage
40 | Xcode.SourceCodeLanguage.Swift
41 | IDECodeSnippetSummary
42 | UITableViewDelegate snippet for Swift
43 | IDECodeSnippetTitle
44 | Swift UITableViewDelegate
45 | IDECodeSnippetUserSnippet
46 |
47 | IDECodeSnippetVersion
48 | 2
49 |
50 |
51 |
--------------------------------------------------------------------------------
/swift-uiviewcontrollerlifecycle.codesnippet:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDECodeSnippetCompletionPrefix
6 | swift-uiviewcontrollerlifecycle
7 | IDECodeSnippetCompletionScopes
8 |
9 | ClassImplementation
10 |
11 | IDECodeSnippetContents
12 | //MARK: UIViewController lifecycle
13 |
14 | override func viewDidLoad() {
15 | super.viewDidLoad()
16 |
17 | }
18 |
19 | override func viewWillAppear(_ animated: Bool) {
20 | super.viewWillAppear(animated)
21 |
22 | }
23 |
24 | override func viewDidAppear(_ animated: Bool) {
25 | super.viewDidAppear(animated)
26 |
27 | }
28 |
29 | override func viewWillDisappear(_ animated: Bool) {
30 | super.viewWillDisappear(animated)
31 |
32 | }
33 |
34 | override func viewDidDisappear(_ animated: Bool) {
35 | super.viewDidDisappear(animated)
36 |
37 | }
38 | IDECodeSnippetIdentifier
39 | 7D773810-8010-450A-B8A1-E66A92969E25
40 | IDECodeSnippetLanguage
41 | Xcode.SourceCodeLanguage.Swift
42 | IDECodeSnippetSummary
43 | UIViewController lifecycle snippet for Swift
44 | IDECodeSnippetTitle
45 | Swift UIViewController lifecycle
46 | IDECodeSnippetUserSnippet
47 |
48 | IDECodeSnippetVersion
49 | 2
50 |
51 |
52 |
--------------------------------------------------------------------------------
/swift-urlsession-datatask.codesnippet:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDECodeSnippetCompletionPrefix
6 | swift-urlsession-datatask
7 | IDECodeSnippetCompletionScopes
8 |
9 | All
10 |
11 | IDECodeSnippetContents
12 | let session = URLSession.shared
13 | let task = session.dataTask(with: <#request#>){ (data, response, error) in
14 | <#code#>
15 | }
16 | task.resume()
17 |
18 | IDECodeSnippetIdentifier
19 | DCE70F58-6A51-4C26-AF88-2F646406A746
20 | IDECodeSnippetLanguage
21 | Xcode.SourceCodeLanguage.Swift
22 | IDECodeSnippetSummary
23 | Swift Simple HTTP Request
24 | IDECodeSnippetTitle
25 | Swift URLSession DataTask
26 | IDECodeSnippetUserSnippet
27 |
28 | IDECodeSnippetVersion
29 | 2
30 |
31 |
32 |
--------------------------------------------------------------------------------
/swift-urlsession-delegate.codesnippet:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDECodeSnippetCompletionPrefix
6 | swift-urlsession-delegate
7 | IDECodeSnippetCompletionScopes
8 |
9 | All
10 |
11 | IDECodeSnippetContents
12 | let session = URLSession(configuration: .default, delegate: self, delegateQueue: nil)
13 | let task = session.dataTask(with: <#request#>){ (data, response, error) in
14 | <#code#>
15 | }
16 | task.resume()
17 |
18 | IDECodeSnippetIdentifier
19 | B03099E0-1094-412E-BE86-5AC1BDB07315
20 | IDECodeSnippetLanguage
21 | Xcode.SourceCodeLanguage.Swift
22 | IDECodeSnippetSummary
23 | Swift HTTP Request With Delegate set
24 | IDECodeSnippetTitle
25 | Swift URLSession With Delegate
26 | IDECodeSnippetUserSnippet
27 |
28 | IDECodeSnippetVersion
29 | 2
30 |
31 |
32 |
--------------------------------------------------------------------------------
/swift-weak.codesnippet:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDECodeSnippetCompletionPrefix
6 | swift-weak
7 | IDECodeSnippetCompletionScopes
8 |
9 | CodeExpression
10 |
11 | IDECodeSnippetContents
12 | [weak self] in
13 | guard let `self` = self else { return }
14 | IDECodeSnippetIdentifier
15 | B5FFB5B9-1B62-49B5-B1E1-0749BBE07D42
16 | IDECodeSnippetLanguage
17 | Xcode.SourceCodeLanguage.Swift
18 | IDECodeSnippetSummary
19 | weakify self in closure
20 | IDECodeSnippetTitle
21 | Swift weakify self
22 | IDECodeSnippetUserSnippet
23 |
24 | IDECodeSnippetVersion
25 | 2
26 |
27 |
28 |
--------------------------------------------------------------------------------