You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: Readme.md
+24-21
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,8 @@
1
1
# Xcode Swift Code Snippets
2
2
3
-
I want to present you some convenient code snippets I gathered for [Swift](https://developer.apple.com/swift/).
3
+
I want to present some convenient code snippets I gathered for [Swift](https://developer.apple.com/swift/).
4
4
5
-
### All snippets are updated to **Swift 3** ❤️
5
+
### All snippets are updated to **Swift 4** ❤️
6
6
7
7
## Inspiration
8
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.
@@ -16,15 +16,15 @@ You can simply copy all code snippets (`.codesnippet`) into this folder, restart
16
16
Note: Create the folder if it doesn't exist already. It is created by Xcode when user adds his first custom snippet.
17
17
18
18
## Usage
19
-
I named all of 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.
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
20
21
-

21
+

22
22
23
23
## How to create your own snippets
24
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 to early you'll probably only deselect text; you can also try dragging from a whitespace instead of the letter).
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).
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.
@@ -33,30 +33,33 @@ If you want to add this nice placeholder in rounded blue rect simply put it betw
33
33
Currently existing snippets (I hope they will be updated on a regular basis with your help :) ):
34
34
35
35
```
36
-
swift-closureoptionaltypealias Optional closure typealiast with arguments and return value snippet for Swift
37
-
swift-closuretypealias Closure typealias with arguments and return value snippet for Swift
38
-
swift-prop Auto-Create property stub
39
-
swift-didbecomeactive UIApplicationDidBecomeActiveNotification observer snippet for Swift
36
+
swift-documentdirectory Document directory path snippet for Swift
40
37
swift-dispatchafter GCD dispatch_after snippet for Swift
38
+
41
39
swift-dispatchasync GCD dispatch_async snippet for Swift
40
+
swift-nslocalizedstring NSLocalizedString function snippet for Swift
42
41
swift-dispatchmain GCD dispatch_async on main queue snippet for Swift
43
-
swift-documentdirectory Document directory path 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
44
45
swift-forin for-in loop that casts objects inline
45
-
swift-iba Create IBAction method stub
46
46
swift-ibo Stub out IBOutlet
47
-
swift-mail MFMailComposeViewController snippet for Swift
48
-
swift-mark Divider label for separating code into sections
49
-
swift-message MFMessageComposeViewController snippet for Swift
50
-
swift-nslocalizedstring NSLocalizedString function snippet for Swift
51
-
swift-singleton Singleton pattern for Swift
52
47
swift-sortarrayofstrings Swift String Array locale-aware sorting
53
-
swift-uicollectionviewdatasource UICollectionViewDataSource snippet for Swift
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
54
53
swift-uicollectionviewdelegate UICollectionViewDelegate snippet for Swift
55
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
56
62
swift-uitableviewdatasource UITableViewDataSource snippet for Swift
57
-
swift-uitableviewdelegate UITableViewDelegate snippet for Swift
58
-
swift-uiviewcontrollerlifecycle UIViewController lifecycle snippet for Swift
0 commit comments