• Stars
    star
    1,755
  • Rank 26,530 (Top 0.6 %)
  • Language
    Python
  • License
    MIT License
  • Created almost 10 years ago
  • Updated over 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Swift 4 code snippets for Xcode

Xcode Swift Code Snippets

I want to present some convenient code snippets I gathered for Swift.

All snippets are updated to Swift 4 ❤️

Inspiration

I was inspired by Matt Thompson's Xcode-Snippets article and GitHub repo but I haven't found anything similar for Swift.

I also used that thing in swift and SwiftSingleton as a sample implementations.

How to import all code snippets to Xcode

All Xcode code snippets exist as a .plist files in ~/Library/Developer/Xcode/UserData/CodeSnippets/ You can simply copy all code snippets (.codesnippet) into this folder, restart Xcode and you should have all of them ready to use.

Note: Create the folder if it doesn't exist already. It is created by Xcode when user adds his first custom snippet.

Usage

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.

Xcode use Swift code snippets

How to create your own snippets

To add code snippet to Xcode expand Utilities right panel and press {} button (Show the Code Snippet library) in lower panel. 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).

Xcode create code snippet

Placeholder tokens

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.

Snippets

Currently existing snippets (I hope they will be updated on a regular basis with your help :) ):

swift-documentdirectory              Document directory path snippet for Swift
swift-dispatchafter                  GCD dispatch_after snippet for Swift

swift-dispatchasync                  GCD dispatch_async snippet for Swift
swift-nslocalizedstring              NSLocalizedString function snippet for Swift
swift-dispatchmain                   GCD dispatch_async on main queue snippet for Swift
swift-closuretypealias               Closure typealias with arguments and return value snippet for Swift
swift-weak                           weakify self in closure
swift-uitableviewdelegate            UITableViewDelegate snippet for Swift
swift-forin                          for-in loop that casts objects inline
swift-ibo                            Stub out IBOutlet
swift-sortarrayofstrings             Swift String Array locale-aware sorting
swift-prop                           Auto-Create property stub
swift-closureoptionaltypealias       Optional closure typealiast with arguments and return value snippet for Swift
swift-urlsession-delegate            Swift HTTP Request With Delegate set
swift-message                        MFMessageComposeViewController snippet for Swift
swift-uiviewcontrollerlifecycle      UIViewController lifecycle snippet for Swift
swift-uicollectionviewdelegate       UICollectionViewDelegate snippet for Swift
swift-uiremotenotification           UIRemoteNotification registration and handling snippet for Swift
swift-mark                           Divider label for separating code into sections
swift-didbecomeactive                UIApplicationDidBecomeActiveNotification observer snippet for Swift
swift-urlsession-datatask            Swift Simple HTTP Request
swift-mail                           MFMailComposeViewController snippet for Swift
swift-iba                            Create IBAction method stub
swift-uicollectionviewdatasource     UICollectionViewDataSource snippet for Swift
swift-singleton                      Singleton pattern for Swift
swift-uitableviewdatasource          UITableViewDataSource snippet for Swift
swift-uiapplicationdelegate          Commonly used app life cycle methods
swift-elegantmark                    Decorates mark statements and makes it neat when looking through items in File Jump Bar

More snippets?

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. You can use plist/generate_list.py script to generate snippets list by running: python generate_list.py.

Do you like it?

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!

More Repositories

1

KBRoundedButton

KBRoundedButton allows you to create beautiful rounded rect button with dynamic colors and activity indicator, completely in Interface Builder.
Objective-C
101
star
2

UIForLumberjack

iOS UI library to display CocoaLumberjack logs on iOS device
Objective-C
63
star
3

KBContactsSelection

Easily search and select contacts in your iOS Address Book and redirect to Mail or Messages with results.
Objective-C
62
star
4

Camouflage

Read and write NSData to iOS Camera Roll as .bmp file and share it between apps!
C
48
star
5

AFAbstractRESTClient

simple abstract solution to deal with REST webservices using AFNetworking
Objective-C
30
star
6

SwiftTeamSelect

Swift implementation of SpriteKit SKScene with scrollable team selection
Swift
27
star
7

AppSettings

Simple tool to allow automatically serialize and deserialize objects to NSDictionary. Originally created to simply manage app settings in NSUserDefaults.
Objective-C
22
star
8

UITableViewCellAnimation

Animating UITableViewCell size and text change using Auto Layout and automatic dimension
Swift
15
star
9

SynchroKit

framework that helps syncing data in iOS environment
Objective-C
9
star
10

NetworkLib

CocoaPods static library test project
Objective-C
6
star
11

ReposBrowser

CocoaPods project that uses NetworkLib as local library
Objective-C
4
star
12

CalendarInvitesCleaner

python script for cleaning pending OS X Calendar.app invites
Python
3
star
13

ReposBrowserStatic

CocoaPods project that uses NetworkLib as static library
Objective-C
2
star
14

SubTrans

Subtitles Translation Helper
Java
2
star
15

SynchroKitTesterServer

django server app for SynchroKitTester
Python
1
star
16

SynchroKitTester

Objective-C
1
star
17

AutolayoutExample

Example project showing how to reset NSLayoutConstraints after a change
Objective-C
1
star
18

ParseCollectionsSwiftBug

Swift
1
star