Skip to content

Instantly share code, notes, and snippets.

View josh-marasigan's full-sized avatar

Josh Marasigan josh-marasigan

View GitHub Profile
class Mom {
var _son: Son
init(son: Son) {
self._son = son
}
func tellJoshWhatToDo() {
self._son.washDishes()
self._son.cleanRoom()
class Son: MomDelegate {
func washDishes() {
print("Washing Dishes")
}
func cleanRoom() {
print("Cleaning Room")
}
protocol MomDelegate {
func washDishes()
func cleanRoom()
func walkNala()
}
// Ran in the same codeblock
var box1: String?
if let boxContents = box1 {
print(boxContents)
}
---
Nothing Prints
var box2: String? = "Something"
if let boxContents = box2 {
// Within a function
var box: String? = "Something"
guard let boxContents = box else { return }
print(boxContents)
---
"Something"
var box: String?
print(box!)
var box: String? = "Something"
>>>
print(box!)
---
"Something"
var box: String?
>>>
print(box!)
---
// This is an optional value
var box : String?
// This is an optional value set to an actual value
var box : String? = "Something"