../
swift-moc
Variables
varfor variablesletfor constants. Constants are recommended
Data Types
IntDouble
Strings
- Double quotes
- Escape quotes with a backslash if they are to be a part of the string
- Multiline strings with
"""
String interpolation
- Use
\()with the variable name in between the parentheses to substitute the value of the variable in to the string My name is \(name) and I am \(age) years old
Arrays
var arr: [Int] = [Int]()
arr.append(1)
Dictionary
var myDict = [
"key": 34
"key2": 35
]
print(myDict["key"] + myDict["key2"] + myDict["not_a_key", default: 0])
Set
var x = Set([1, 2, 3])
x.insert(35)
Enum
enum Weekday {
case monday, tuesday, thursday, friday, saturday, sunday
}
let day: Weekday
day = .tuesday