Title: Theory / Unimportant / CS / Programming / Swift

Instruction: let varName = value
Page: https://www.swift.org/getting-started/
Meaning: A non-mutable value initialized to value
Language: swift
Chapter: getting started
Identifier: varName
Mutable: no

Instruction: swift
Page: https://www.swift.org/getting-started/
Effect: start swift repl
Language: sh

Variable: Package.swift
Meaning: File declaring parameter of the current folder as a swift module
Page: https://www.swift.org/getting-started/

Fla: package init
Effect: Transform current directory into a package
Page: https://www.swift.org/getting-started/
Prefix: swift

Fla: build
Effect: build current package
Page: https://www.swift.org/getting-started/
Prefix: swift

Fla: test
Effect: run the tests of the current package
Page: https://www.swift.org/getting-started/
Prefix: swift

Variable: main.swift
Meaning: File containing the starting code of an executable
Page: https://www.swift.org/getting-started/

Fla: the package is an executable
Effect: --type executable
Page: https://www.swift.org/getting-started/
Prefix: swift package init

Instruction: func functionName(arg_name_1 local_name_1: type_1, ..., arg_n local_name_n: type_n) {
  block
}
Page: https://www.swift.org/getting-started/
Meaning: A function taking arguments arg_name_i of type type_i. When it's called, it executes block with the value passed to arg_name_i is assigned to local_name_i.
Identifier: functionName

Instruction: if cond {
  trueCase
} else {
  falseCase
}
Page: https://www.swift.org/getting-started/
Effect: Execute cond, if it holds, trueCase otherwise falseCase

Instruction: swiftc foo.swift
Page: https://www.swift.org/getting-started/
Effect: Create an executable foo, executing code from swift

Fla: -g
Effect: ensure executable can be debugged with lldb
Page: https://www.swift.org/getting-started/
Prefix: swiftc

Instruction: print(foo)
Page: https://www.swift.org/getting-started/
Effect: Print foo on stdout
Language: swift

Instruction: var variableName = value
Page: https://www.swift.org/getting-started/
Meaning: Initialize a new variable with value
Language: swift
Identifier: variableName
Mutable: yes

Instruction: variableName = value
Page: https://www.swift.org/getting-started/
Effect: change the value assigned to variableName to value
Language: swift

Instruction: let|var valrName: Type = value
Page: https://www.swift.org/getting-started/
Meaning: also ensure that valrName's type is value
Language: swift
Similar to: let|var varName = value

Instruction: \( expr )
Page: https://www.swift.org/getting-started/
Effect: Insert there String(expr)
Language: swift
Context: string

Instruction: """
some
string
"""
Page: https://www.swift.org/getting-started/
Language: swift
Context: string
Returns: A multi line string

Instruction: [value_0, ..., value_n]
Page: https://www.swift.org/getting-started/
Language: swift
Context: string
Returns: A mutable array (even in size) of n+1 elements with i-th element value_i

Instruction: [key_0: value_0,
  ...,
  key_n: value_n]
Page: https://www.swift.org/getting-started/
Language: swift
Context: string
Returns: A dictionary from key_i to value_i

Instruction: ar[i]
Page: https://www.swift.org/getting-started/
Language: swift
Context: string
Returns: The i-th element of the array
Variables: ar an Array

Instruction: dict[key]
Page: https://www.swift.org/getting-started/
Language: swift
Context: string
Returns: The element of dict associated to dict
Variables: dict a dictionary
key a key

Instruction: [:]
Page: https://www.swift.org/getting-started/
Language: swift
Context: string
Returns: An empty dictionnary

Typ: [Type]
Meaning: Mutable arrays whose values are [type]
Page: https://www.swift.org/getting-started/
Language: swift
Context: string

Typ: [KeyType: ValueType]
Meaning: Mutable dictionnaries from KeyType to ValueType
Page: https://www.swift.org/getting-started/
Language: swift
Context: string

Instruction: for elt in iterable {
  block
}
Page: https://www.swift.org/getting-started/
Effect: execute block once for each element elt in iterable
Language: swift

Typ: Type?
Meaning: Either Type or the constant nil
Page: https://www.swift.org/getting-started/
Language: swift

Instruction: if let value = optionalValue {
  block
}
Page: https://www.swift.org/getting-started/
Effect: If optionalValue is not nil, execute block; where value is known to be the non-nil optionalValue
Language: swift
Variables: optionalValue: Type?
Typ: Type?

Instruction: optionalValue ?? otherValue
Page: https://www.swift.org/getting-started/
Language: swift
Returns: The non-nil optionalValue or otherValue
Variables: optionalValue: Type?
Typ: Type

Page: https://www.swift.org/getting-started/
Syntactic sugar: if let optionalValue {
  block
}
Implementation: if let optionValue = optionalValue {
  block
}
Language: swift
Variables: optionalValue: Type?

Instruction: switch expr {
  case pattern_0:
    block_0
  ..
  case pattern_n:
    block_n
  default:
    default_block
}
Page: https://www.swift.org/getting-started/
Effect: for i the first pattern_i that matches agains the value of expr, execute block_i
Language: swift

Page: https://www.swift.org/getting-started/
Syntactic sugar: case pattern_0, ..., pattern_n:
    block
Implementation: case pattern_0,
  block
...
case pattern_n:
    block
Language: swift

Instruction: while pred {
  block
}
Page: https://www.swift.org/getting-started/
Effect: if pred do not hold, do nothing.
Otherwise execute block and restart this entire effect
Language: swift

Instruction: repeat {
  block
} while pred
Page: https://www.swift.org/getting-started/
Effect: execute block
If pred hold, reexecute this whole effect
Language: swift

Instruction: i..<j
Page: https://www.swift.org/getting-started/
Language: swift
Returns: range from i included to j excluded

Instruction: i...j
Page: https://www.swift.org/getting-started/
Language: swift
Returns: range from i included to j included

Instruction: return expr
Page: https://www.swift.org/getting-started/
Effect: end the execution of the current function and return value of expr
Language: swift

Instruction: func functionName(arg_name_1 local_name_1: type_1, ..., arg_n local_name_n: type_n)  -> returnType {
  block
}
Page: https://docs.swift.org/swift-book/GuidedTour/GuidedTour.html
Meaning: also indicate that the function return a value of type returnType
Identifier: functionName
Similar to: func functionName(arg_name_1 local_name_1: type_1, ..., arg_n local_name_n: type_n)  {
  block
}

Instruction: _ argName: type
Page: https://docs.swift.org/swift-book/GuidedTour/GuidedTour.html
Meaning: argName don't need an argument label when its function is called
Context: function declaration

Instruction: functionName(arg_name_1: expr_1, ..., arg_name_n: expr_n)
Page: https://docs.swift.org/swift-book/GuidedTour/GuidedTour.html
Effect: Call functionName, with arg_name_i assigned to the value of expr_i
Language: swift
Variables: func functionName(arg_name_1 local_name_1: type_1, ..., arg_n local_name_n: type_n)  -> returnType

Page: https://docs.swift.org/swift-book/GuidedTour/GuidedTour.html
Syntactic sugar: argName: type
Implementation: argName argName: type
Language: swift
Context: function declaration

Typ: (
  arg_name_0: type_0
  ...
  arg_name_n: type_n
)
Meaning: An n-tuple whose i-th element is called arg_name_i and have type_i
Page: https://docs.swift.org/swift-book/GuidedTour/GuidedTour.html
Language: swift

Instruction: tuple.arg_name_i
Page: https://docs.swift.org/swift-book/GuidedTour/GuidedTour.html
Language: swift
Returns: the value associated to arg_name_i in tuple
Variables: tuple: (
  arg_name_0: type_0
  ...
  arg_name_n: type_n
)
Abbreviation: tuple.i

Instruction: (
  expr_0,
  ...
  expr_n
)
Page: https://docs.swift.org/swift-book/GuidedTour/GuidedTour.html
Language: swift
Returns: The tuple whose i-th value is expr_i

Instruction: {(args)-> returnType in block}
Page: https://docs.swift.org/swift-book/GuidedTour/GuidedTour.html
Language: swift
Returns: A method taking args, exeecuting block which returns returnType

Page: https://docs.swift.org/swift-book/GuidedTour/GuidedTour.html
Syntactic sugar: {arg in expr}
Implementation: {(arg: inferredType) exprType in expr}
Language: swift

Variable: $i
Meaning: The ith argument of the closure
Page: https://docs.swift.org/swift-book/GuidedTour/GuidedTour.html
Context: closure
Language: swift

Page: https://docs.swift.org/swift-book/GuidedTour/GuidedTour.html
Syntactic sugar: functionName { closureContent}
Implementation: functionName({ closureContent})
Language: swift

Instruction: object.propertyName
Page: https://docs.swift.org/swift-book/GuidedTour/GuidedTour.html
Language: swift
Returns: The value associated to propertyName in object
Variables: object: Class

Instruction: object.methodName(args)
Page: https://docs.swift.org/swift-book/GuidedTour/GuidedTour.html
Language: swift
Returns: Call methodName(args) on receiver object
Variables: object: Class

Question: If a class has no explicit init, how to initialize it
Answer: it has an implicit init() which does nothing
Page: https://docs.swift.org/swift-book/GuidedTour/GuidedTour.html
Context: swift

Instruction: init(args) {
  block
}
Page: https://docs.swift.org/swift-book/GuidedTour/GuidedTour.html
Effect: Object of type C can be initialized with C(args), which does block
Language: swift
Context: class C

Instruction: self.propertyName
Page: https://docs.swift.org/swift-book/GuidedTour/GuidedTour.html
Language: swift
Context: class C method call
Returns: The value of propertyName in the object which received the method call

Instruction: deinit() {
  block
}
Page: https://docs.swift.org/swift-book/GuidedTour/GuidedTour.html
Effect: when an object of type C is destructed, execute block
Language: swift
Context: class C

Instruction: class ClassName: parentClassName {
  decls
}
Page: https://docs.swift.org/swift-book/GuidedTour/GuidedTour.html
Meaning: extends parentClassName, and add everything from decls in this new class
Language: swift
Identifier: ClassName

Instruction: var propertyName: Type{
  get {
    return getBlock
  }
  set {
    setBlock
  }
}
Page: https://docs.swift.org/swift-book/GuidedTour/GuidedTour.html
Meaning: when property propertyName is accessed, execute getBlock. When setting it, execute setBlock
Language: swift
Context: class
Identifier: propertyName

Instruction: super.methodName(args)
Page: https://docs.swift.org/swift-book/GuidedTour/GuidedTour.html
Effect: call methodName as implemented in super class
Language: swift
Context: class

Instruction: override functionName(args) declaration
Page: https://docs.swift.org/swift-book/GuidedTour/GuidedTour.html
Meaning: Same as
functionName(args) declaration
but guarantee its hiding a method with same type and name in parent class
Language: swift
Context: class

Instruction: willSet { block }
Page: https://docs.swift.org/swift-book/GuidedTour/GuidedTour.html
Meaning: after the current varName is set, execute block
Language: swift
Context: var varName declaration

Instruction: didSet { block }
Page: https://docs.swift.org/swift-book/GuidedTour/GuidedTour.html
Meaning: before the value of varName is changed, execute block
Language: swift
Context: var varName declaration

Instruction: optional?.foo
Page: https://docs.swift.org/swift-book/GuidedTour/GuidedTour.html
Effect: execute foo on receiver optional if optional is not nil
Language: swift
Variables: optional: Type?

Instruction: enum enumName: IntType {
  case case_name_0
  ...
  case case_name_n
  decl
}
Page: https://docs.swift.org/swift-book/GuidedTour/GuidedTour.html
Meaning: Introduce a class enumName with contants case_name_i's
Language: swift

Instruction: enum.rawValue
Page: https://docs.swift.org/swift-book/GuidedTour/GuidedTour.html
Language: swift
Returns: the integral value associated to rawValue
Variables: enum enumName: IntType {
  case case_name_0
  ...
  case case_name_n
}
value: enumName

Instruction: enumName(rawValue: i)
Page: https://docs.swift.org/swift-book/GuidedTour/GuidedTour.html
Language: swift
Returns: the case_name_i whose raw value is i
Variables: enum enumName: IntType {
  case case_name_0
  ...
  case case_name_n
}
i: IntType

Page: https://docs.swift.org/swift-book/GuidedTour/GuidedTour.html
Syntactic sugar: .case_name_i
Implementation: enumeName.case_name_i
Language: swift
Variables: enum enumName: IntType {
  case case_name_0
  ...
  case case_name_n
}
Assuming: type enumName is determined by context

Question: Difference between struct and class
Answer: struct are placed by value and class by reference
Page: https://docs.swift.org/swift-book/GuidedTour/GuidedTour.html
Chapter: swift
Assuming: type enumName is determined by context