This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Mom { | |
var _son: Son | |
init(son: Son) { | |
self._son = son | |
} | |
func tellJoshWhatToDo() { | |
self._son.washDishes() | |
self._son.cleanRoom() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Son: MomDelegate { | |
func washDishes() { | |
print("Washing Dishes") | |
} | |
func cleanRoom() { | |
print("Cleaning Room") | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol MomDelegate { | |
func washDishes() | |
func cleanRoom() | |
func walkNala() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Ran in the same codeblock | |
var box1: String? | |
if let boxContents = box1 { | |
print(boxContents) | |
} | |
--- | |
Nothing Prints | |
var box2: String? = "Something" | |
if let boxContents = box2 { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Within a function | |
var box: String? = "Something" | |
guard let boxContents = box else { return } | |
print(boxContents) | |
--- | |
"Something" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var box: String? | |
print(box!) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var box: String? = "Something" | |
>>> | |
print(box!) | |
--- | |
"Something" | |
var box: String? | |
>>> | |
print(box!) | |
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is an optional value | |
var box : String? | |
// This is an optional value set to an actual value | |
var box : String? = "Something" |
NewerOlder