Question regarding class property default value

I’m reading Apple’s official Swift mannual (, and there’s something in the mannual that I don’t really understand.


class Country {

  let name: String

  var capitalCity: City!

  init(name: String, capitalName: String) { = name

  self.capitalCity = City(name: capitalName, country: self)




class City {

  let name: String

  unowned let country: Country

  init(name: String, country: Country) { = name = country



Apple says: “Because capitalCity has a default nil value, a new Country instance is considered fully initialized as soon as the Country instance sets its name property within its initializer.”


But how does capitalCity have a default nil value? The code only says capitalCity takes values of type City!, but capitalCity has not been assigned any value yet. It says var capitalCity: City! not var capitalCity = City! .  So how can it have a default nil value already?

Powered by WPeMatico

You may also like...

Comments are closed.