My Profile Photo

Hao's Keeper


A blog to place memos


Swift Optional Chaining

Optional Chaining

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.