head.daveops.net

Snippets for yer computer needs

swift

Benefits

Variables initialized before use

CLI

swift - start up a Swift REPL (backed by LLDB) swiftc - compile swift code

Syntax cheatsheet

No semicolons needed No main() needed, global scope is entry point Values are never implicitly converted to another type

String interpolation: “The building is (feet) feet tall”

let multi_line_string = """
multi
line
string
"""

let dictionary = [
  "hotpotato": 1,
  "coldpotato" 2
]

let empty_dict = [:]

if boolean_var {
  print("this is true")
}

var optionalString: String? = "Maybe hello?"