Swift类多重继承
我创建了这样一个类:Swift类多重继承,swift,class,multiple-inheritance,Swift,Class,Multiple Inheritance,我创建了这样一个类: class number1: UIScrollView { init() { super.init(frame: CGRect(x: 9, y: 780, width: 1024, height: 267)) self.contentSize = CGSize(width: 100, height: 267) self.backgroundColor = UIColor.clear self.autoresizingMask = UIVie
class number1: UIScrollView {
init() {
super.init(frame: CGRect(x: 9, y: 780, width: 1024, height: 267))
self.contentSize = CGSize(width: 100, height: 267)
self.backgroundColor = UIColor.clear
self.autoresizingMask = UIView.AutoresizingMask(rawValue: UIView.AutoresizingMask.RawValue(UInt8(UIView.AutoresizingMask.flexibleWidth.rawValue)))
//followed by do blablabla I dont want in my new class
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
现在我想要一个类似于我的一等的二等舱,但是没有布拉
class number2: number1 {
override init() {
super.init()
self.frame = CGRect(x: 400, y: 10, width: 196, height: 500)
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
我这样做,但不知道如何删除“布拉布拉”。最简单的方法是从UIScrollView继承init,而不是从类number1继承。如何做到这一点?这里只是简单介绍一下,但应该足够了:
class number1: UIScrollView {
init() {
super.init()
// Do stuff common to all classes
setup()
}
func setup() {
// Do stuff for this class
}
}
class number2: number1 {
override func setup() {
// Do stuff for this class only
}
}
这里只是简单的介绍,但应该足够了:
class number1: UIScrollView {
init() {
super.init()
// Do stuff common to all classes
setup()
}
func setup() {
// Do stuff for this class
}
}
class number2: number1 {
override func setup() {
// Do stuff for this class only
}
}