-
implicit variables and immutable variables
-
explicit variables
-
values need to be explicitly converted
-
use () to convert a variable to a string (in quotes)
-
arrays and dictionaries
- implicit and explicit variable data types
- strings
- string interpolation ()
- chars (converting string to array of chars).
- arrays
- introspection (type)
- enumerated
- characters
- repeat while
- conditional (if)
- optionals
- exit (quit script with exit code)
- enumerations (errors)
- exception handling & throwing errors
- guard let else
- switch
- type of
- declaring functions
- return types
- unused vars
_
- functions that throw errors
let colours:[String] = ["red", "orange", "green"]
print(colours.count)
print("\(colours)")
var shoppingList = [String]()
//shoppingList.append("bread")
shoppingList += ["Bread"]
shoppingList.append("butter")
print("\(shoppingList)")
for item in shoppingList {
print("\(item)")
}
var book = [
"isbn": "1491943122",
"title": "Learning Node"
]
var ages = [String:Int]()
ages["john"] = 42
ages["jane"] = 24
print("\(ages)")
for (name, age) in ages {
print("\(name) is \(age) years old")
}
struct
// normally functions use their parameter names as labels so you need to have a custom argument label before each parameter name.
func printPerson(withName name:String, andAge age:Int) {
print("\(name) is \(age) years old")
}
printPerson(withName: "frank", andAge: 64)
// use _ if you want to omit the first argument label.
func add(_ num1:Int, and num2:Int) -> Int {
return num1 + num2
}
print(add(24, and: 42))
- objects and classes
- importing from separate file
- create instance by putting parenthesis before class name.
- private instance variables
- properties (getters and setters)
- methods
- static
- closures (callbacks)
- importing XCUnit