Skip to content
Permalink
fd1f47512d
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
75 lines (60 sloc) 1.38 KB
/*
SWIFT TOUR
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
*/
// array
let colours:[String] = ["red", "orange", "green"]
print(colours.count)
print("\(colours)")
var shoppingList = [String]()
shoppingList.append("bread")
shoppingList.append("butter")
print("\(shoppingList)")
for item in shoppingList {
print("\(item)")
}
// dictionary
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")
}
// 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))
// OOP
/*
objects and classes
importing from separate file
create instance by putting parenthesis before class name.
private instance variables
properties (getters and setters)
methods
static
*/
// ASYNC
/*
closures (callbacks)
*/
// FOUNDATION FRAMEWORK
// UNIT TESTING
/*
importing XCUnit
*/