🍮 A collection of Swift snippets to be used in Xcode

Overview

Swift Snippets

❤️ Support my app ❤️

❤️ ❤️ 😇 😍 🤘 ❤️ ❤️

A collection of Swift snippets to be used in Xcode

Usage

  • swifttrycatch
do {
  try <#code#>
} catch <#errortype#> {
  <#code#>
} catch <#errortype#> {
  <#code#>
}
  • swiftassociatedobject
private struct AssociatedKeys {
  static var <#name#> = "<#name#>"
}

var <#name#>: String? {
  get {
    return objc_getAssociatedObject(self, &AssociatedKeys.<#name#>) as? String
  }

  set {
    if let newValue = newValue {
      objc_setAssociatedObject(self, &AssociatedKeys.<#name#>, newValue as String?,
        .OBJC_ASSOCIATION_RETAIN_NONATOMIC
      )
    }
  }
}
  • swiftavailable
@available(iOS 7, *)
  • swiftcheckavailability
if #available(iOS 9, *) {
    <#API available statements#>
} else if #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
public required init?(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
guard let `self` = self else {
  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#>
}

Installation

Manual

Drag codesnippet files from Snippets into /Library/Developer/Xcode/UserData/CodeSnippets

Automatic

Run this in your terminal

curl -fsSL https://raw.githubusercontent.com/hyperoslo/SwiftSnippets/master/install.sh | sh

Author

Credit

License

SwiftSnippets is available under the MIT license. See the LICENSE file for more info.

You might also like...
OysterKit is a framework that provides a native Swift scanning, lexical analysis, and parsing capabilities. In addition it provides a language that can be used to rapidly define the rules used by OysterKit called STLR

OysterKit A Swift Framework for Tokenizing, Parsing, and Interpreting Languages OysterKit enables native Swift scanning, lexical analysis, and parsing

A general purpose embedded hierarchical lock manager used to build highly concurrent applications of all types. Same type of locker used in many of the large and small DBMSs in existence today.

StickyLocking StickyLocking is a general purpose embedded lock manager which allows for locking any resource hierarchy. Installable Lock modes allow f

Strucure: I used MVVM with Colusre binging modular architecture : Also I used openweathermap to get all information for current weather as it's easy t
Strucure: I used MVVM with Colusre binging modular architecture : Also I used openweathermap to get all information for current weather as it's easy t

Strucure: I used MVVM with Colusre binging modular architecture : Also I used openweathermap to get all information for current weather as it's easy t

Twitter Text Libraries. This code is used at Twitter to tokenize and parse text to meet the expectations for what can be used on the platform.

twitter-text This repository is a collection of libraries and conformance tests to standardize parsing of Tweet text. It synchronizes development, tes

Horizontal and Vertical collection view for infinite scrolling that was designed to be used in SwiftUI
Horizontal and Vertical collection view for infinite scrolling that was designed to be used in SwiftUI

InfiniteScroller Example struct ContentView: View { @State var selected: Int = 1 var body: some View { InfiniteScroller(direction: .ve

A collection of common tools and commands used throughout the development process, customized for Kipple projects.

KippleTools A collection of common tools and commands used throughout the development process, customized for Kipple projects. ⚠️ The code in this lib

Modern-collection-view - Modern collection view for swift

Modern collection view Sample application demonstrating the use of collection vi

A command-line tool to generate a JSON-list of all used SPM-dependencies of an Xcode-project.

SwiftPackageList A command-line tool to generate a JSON-list of all used SPM-dependencies of an Xcode-project. This includes all the Package.resolved

LiberIOS - LiberIOS used Xcode and SwiftUI
LiberIOS - LiberIOS used Xcode and SwiftUI

LiberIOS For this test, i have used Xcode and SwiftUI. For the authentication i

This repository contains rules for Bazel that can be used to generate Xcode projects

rules_xcodeproj This repository contains rules for Bazel that can be used to generate Xcode projects. If you run into any problems with these rules, p

Blueprints is a collection of flow layouts that is meant to make your life easier when working with collection view flow layouts.
Blueprints is a collection of flow layouts that is meant to make your life easier when working with collection view flow layouts.

Blueprints is a collection of flow layouts that is meant to make your life easier when working with collection view flow layouts. It comes

A patch collection to save your Xcode
A patch collection to save your Xcode

Patch Xcode is worst IDE I have ever used Xcode 13.3 introduced a very annoying bug. When you type anything with Chinese IME in the LLDB console

Xcode-streamdeck-plugin - A Stream Deck plugin for Xcode
Xcode-streamdeck-plugin - A Stream Deck plugin for Xcode

Stream Deck Xcode Plugin This repository contains a Stream Deck plugin to add so

XTextHandler - Xcode Source Editor Extension Tools (Xcode 8 Plugins)
XTextHandler - Xcode Source Editor Extension Tools (Xcode 8 Plugins)

Download Let's Swift! xTextHandler has been rewritten in Swift. The Objective-C version can be found in: https://github.com/cyanzhong/xTextHandler-obj

Awesome-xcode-scripts - A curated list of useful xcode scripts 📝 .
Awesome-xcode-scripts - A curated list of useful xcode scripts 📝 .

Awesome Xcode Scripts A curated list of useful Xcode scripts 📝 . Content How to Setup Scripts Build Number Auto-Increment Script Build Number Auto-In

Synx - A command-line tool that reorganizes your Xcode project folder to match your Xcode groups
Synx - A command-line tool that reorganizes your Xcode project folder to match your Xcode groups

A command-line tool that reorganizes your Xcode project folder to match your Xcode groups. Xcode Finder Installation $ gem install synx Usage Basic ⚠

This repository contains 🎨 My Xcode theme that I use. It is compatible with all versions of Xcode.
This repository contains 🎨 My Xcode theme that I use. It is compatible with all versions of Xcode.

DRL Xcodetheme Installation Automatic (via script) ./install.sh which will install the file in Xcode FontAndColorThemes directory. Restart Xcode Go t

LinkedLog is a Xcode plugin that includes a Xcode PCH header file template that adds the macros `LLog` and `LLogF` and parses their output to link from the console to the corresponding file and line.
LinkedLog is a Xcode plugin that includes a Xcode PCH header file template that adds the macros `LLog` and `LLogF` and parses their output to link from the console to the corresponding file and line.

LinkedLog Xcode Plugin LinkedLog is a Xcode plugin that includes a Xcode PCH file template that adds the macros LLog and LLogF. The LLog macro will wo

Xcode plugin that brings ⇧⌘T from AppCode over to Xcode

Aviator An Xcode Plugin that brings ⇧⌘T over to Xcode This minimal plugin allows you to use the key combo ⇧⌘T to toggle between source and test files.

Comments
  • Swift 3 branch

    Swift 3 branch

    Hey @hyperoslo, I'd be cool to add a Swift 3 branch so we could make the necessary changes over there since a lot of methods changed, like the dispatch_async, for example.

    opened by lfarah 2
Owner
Khoa
Check my apps https://onmyway133.com/apps
Khoa
Just For Fun - tiny easy apps, refresher for swift basics

Stanford Swift Education - Very Basic - Refresher Some useful hints: Outlet types: Outlet Action Outlet Collection with Index - very useful Debugger l

Anton Veldanov 0 Nov 14, 2021
A quick reference cheat sheet for common, high level topics in Swift.

Swift 3+ Cheat Sheet Want to help improve this? File an issue or open a pull request! :) This is not meant to be a beginner's guide or a detailed disc

rob phillips 957 Dec 12, 2022
A Swift library for efficient highlighting, indenting, and querying the structure of language syntax.

Neon A Swift library for efficient highlighting, indenting, and querying the structure of language syntax. It features: Minimal text invalidation Supp

Chime 214 Dec 28, 2022
🍮 A collection of Swift snippets to be used in Xcode

Swift Snippets ❤️ Support my app ❤️ Push Hero - pure Swift native macOS application to test push notifications PastePal - Pasteboard, note and shortcu

Khoa 156 Dec 24, 2022
Swift package to interact with Xcode Code Snippets in a type-safe manner

XCSnippets Swift package to provide type-safe interaction with (user-defined) Xcode Code Snippets Overview import XCSnippets let directory = Persiste

Marco Eidinger 4 Oct 11, 2022
Swift package to interact with Xcode Code Snippets in a type-safe manner

XCSnippets Swift package to provide type-safe interaction with (user-defined) Xcode Code Snippets Overview import XCSnippets let directory = Persiste

Marco Eidinger 3 Jun 24, 2022
XcodeCodeSnippets - Code snippets for Xcode.

XcodeCodeSnippets A set of snippets for Xcode. Requirements Xcode 7.3.1 or later. Installation To install or update the snippets you need: Quit Xcode

Ivan Smetanin 33 Oct 14, 2022
An Xcode Plugin to upload code snippets directly into Slack and Gist

XCSnippetr Share code snippets to Slack and Gist without leaving Xcode ever again! ?? Features Upload code snippets using Slack's and Github's APIs. T

Ignacio Romero Zurbuchen 100 Nov 29, 2022
Some helpful swift code snippets

HelpfulSwiftSnippets Some helpful swift code snippets Network Manager - a generic network manager that deals with downloading data from the internet u

null 2 Oct 17, 2021
SnippetsLibrary - Code snippets library for SwiftUI Devs.

SnippetsLibrary is a helpful tool for SwiftUI developers to help with their daily coding life. SnippetsLibrary contains all the needed code snippets for you to view, edit, or add more and more. This will make your daily work easier and faster.

Christopher Lowiec 41 Jan 2, 2023