Skip to content

Instantly share code, notes, and snippets.

@ytyubox
Last active February 25, 2021 08:07
Show Gist options
  • Save ytyubox/81f3fa2ae865812b6acd875cd18844be to your computer and use it in GitHub Desktop.
Save ytyubox/81f3fa2ae865812b6acd875cd18844be to your computer and use it in GitHub Desktop.
# Xcode default code snippets.
## TODO
- [ ]: apply vim-snippets
# Protocol, ["TopLevel", "ClassImplementation"]
snippet protocol
protocol <#name#> {
<#requirements#>
}
# Struct, ["TopLevel", "ClassImplementation"]
snippet struct
struct <#name#> {
<#fields#>
}
# OptionSet, ["TopLevel", "ClassImplementation"]
snippet optionset
struct <#name#>: OptionSet {
let rawValue: <#integer type#>
static let <#optionA#> = <#name#>(rawValue: 1 << 0)
static let <#optionB#> = <#name#>(rawValue: 1 << 1)
static let <#optionC#> = <#name#>(rawValue: 1 << 2)
static let all: <#name#> = [.<#optionA#>, .<#optionB#>, .<#optionC#>]
}
# Subclass, ["TopLevel", "ClassImplementation"]
snippet class
class <#name#>: <#super class#> {
<#code#>
}
# Enumerated Type Declaration, ["TopLevel", "ClassImplementation"]
snippet enum
enum <#name#> {
case <#case#>
}
# Function Statement, ["TopLevel", "ClassImplementation"]
snippet func
func <#name#>(<#parameters#>) -> <#return type#> {
<#function body#>
}
# If Statement, ["CodeBlock"]
snippet if
if <#condition#> {
<#code#>
}
# Switch Statement, ["CodeBlock"]
snippet switch
switch <#value#> {
case <#pattern#>:
<#code#>
default:
<#code#>
}
# For Statement, ["CodeBlock"]
snippet for
for <#item#> in <#items#> {
<#code#>
}
# While Statement, ["CodeBlock"]
snippet while
while <#condition#> {
<#code#>
}
# Let Declaration, ["TopLevel", "ClassImplementation", "CodeBlock"]
snippet let
let <#name#> = <#value#>
# Var Declaration, ["TopLevel", "ClassImplementation", "CodeBlock"]
snippet var
var <#name#> = <#value#>
# Guard Statement, ["CodeBlock"]
snippet guard
guard <#condition#> else {
<#statements#>
}
# Guard-Let Statement, ["CodeBlock"]
snippet guardlet
guard let <#constant#> = <#expression#> else { return <#return value#> }
# Do-Catch Statement, ["CodeBlock"]
snippet docatch
do {
try <#throwing expression#>
} catch <#pattern#> {
<#statements#>
}
# Computed Variable Get Declaration, ["ClassImplementation"]
snippet varget
var <#variable name#>: <#type#> {
<#statements#>
}
# Computed Variable Get and Set Declaration, ["ClassImplementation"]
snippet vargetset
var <#variable name#>: <#type#> {
get {
<#statements#>
}
set {
<#variable name#> = newValue
}
}
# Defer Statement, ["CodeBlock"]
snippet defer
defer {
<#deferred statements#>
}
# If-Else Statement, ["CodeBlock"]
snippet ifelse
if <#condition#> {
<#statements#>
} else {
<#statements#>
}
# If-Let Statement, ["CodeBlock"]
snippet iflet
if let <#constant name#> = <#optional#> {
<#statements#>
}
# Unwind Segue Method, ["ClassImplementation"]
snippet unwind
@IBAction func unwindTo<#name#>(_ unwindSegue: UIStoryboardSegue) {
let sourceViewController = unwindSegue.source
// Use data from the view controller which initiated the unwind segue
}
# Test Method, ["ClassImplementation"]
snippet test
func test<#Name#>() {
<#statements#>
}
# Lazy Stored Property Declaration, ["ClassImplementation"]
snippet lazyvar
lazy var <#property name#> = <#expression#>
# Lazy Closure Stored Property Declaration, ["ClassImplementation"]
snippet lazyvarclosure
lazy var <#property name#>: <#type name#> = {
<#statements#>
return <#value#>
}()
# Closure Stored Constant Declaration, ["ClassImplementation"]
snippet letclosure
let <#constant name#>: <#type name#> = {
<#statements#>
return <#value#>
}()
# API Availability Check, ["CodeBlock"]
snippet available
if #available(<#{i, mac, tv, watch}#>OS <#x.y.z#>, *) {
<#API available statements#>
} else {
<#fallback statements#>
}
# Typealias Declaration, ["TopLevel", "ClassImplementation", "CodeBlock"]
snippet typealias
typealias <#type name#> = <#type expression#>
# Closure Expression, ["TopLevel", "CodeBlock"]
snippet closure
{ (<#parameters#>) -> <#return type#> in
<#statements#>
}
# Initializer Declaration, ["ClassImplementation"]
snippet init
init(<#parameters#>) {
<#statements#>
}
# Convenience Initializer Declaration, ["ClassImplementation"]
snippet convenienceinit
convenience init(<#parameters#>) {
<#statements#>
}
# Required Initializer Declaration, ["ClassImplementation"]
snippet requiredinit
required init(<#parameters#>) {
<#statements#>
}
# Deinitializer Declaration, ["ClassImplementation"]
snippet deinit
deinit {
<#statements#>
}
# Import Statement, ["TopLevel"]
snippet import
import <#module#>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment