0
說我的UIViewController
有兩個屬性,var animal: String
和var color: UIColor
。如何爲我在Swift中以編程方式創建的UIViewController子類創建init?
如何創建自定義init
,以便我可以在代碼中輕鬆創建此代碼?
我想有:
init(animal: String, color: UIColor) {
self.animal = animal
self.color = color
}
,但我得到的是我不使用指定的初始化一個編譯器錯誤。我在做什麼錯了/我該如何做這件事?
通常在Swift中,應該最後調用super.init。 –
你說得對。更新了答案。 – bvogelzang
super.init()不是UIViewController的指定初始值設定項 – aBikis