Post

Swift Optional Chaining

Swift Optional Chaining

Optional Chaining

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class Address {
	var buildingName: String?
}

class Person {
	var address: Address?
}

func createBuildingName() -> String {
	print("createBuildingName was called.")
	return "12"
}

let john = Person()
john.address?.buildingName = createBuildingName()

nothing was printed, because function was not called.

This post is licensed under CC BY 4.0 by the author.