0

I created a class like this one:

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")
}

Now I want a 2nd class similar to my 1st class but without the blablabla.

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")
}

}

I am doing it this way but dont know how to remove the "blablabla". The easiest would be to inherit the init from UIScrollView instead of class number1. How to do that?

1 Answer 1

4

Just the bare bones here but should be enough:

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
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.