【发布时间】:2014-08-22 16:46:15
【问题描述】:
我有以下类,带有一个 init 方法:
class user {
var name:String
var address:String
init(nm: String, ad: String) {
name = nm
address = ad
}
}
我正在尝试对此类进行子类化,但在 super.init() 部分不断出现错误:
class registeredUser : user {
var numberPriorVisits: Int
// This is where things start to go wrong - as soon as I type 'init' it
// wants to autocomplete it for me with all of the superclass' arguments,
// and I'm not sure if those should go in there or not:
init(nm: String, ad: String) {
// And here I get errors:
super.init(nm: String, ad: String)
// etc....
Apple 的 iBook 有子类化的示例,但没有那些具有 init() 方法且其中包含任何实际参数的功能类。他们所有的 init 都没有参数。
那么,你是怎么做到的呢?
【问题讨论】:
-
我认为你可以(并且应该)通过以大写的方式声明类来使你的代码更简洁?
标签: initialization swift subclass superclass