我有一个类XYZObject
,它继承自ABCObject
的一些初始值设定项和方法:
class XYZObject: ABCObject {
var name: String = ""
init(withName name: String){
self.name = name
}
}
class ABCObject{
internal var jsonstore: JSON
init(withJson newJson: JSON){
jsonstore = newJson
}
}
但是,每当我打电话给XYZObject(withJson: jsonstuff)
时,Swift都会给我错误:Incorrect argument label in call (have 'withJson:', expected 'withName:')
我是swift和iOS开发的新手。我在这里想念的是什么?
感谢您的帮助!
答案 0 :(得分:3)
在Swift中,如果向类添加新的初始值设定项,则类不会继承其基类的初始值设定项。
如果您希望在init(withJson:)
课程中提供XYZObject
,则需要添加它:
override init(withJson newJson: JSON) {
super.init(withJson:newJson)
}