0

I've tried all answers from previous questions but am still getting errors when I try to subclass UIView and add my own initializer. This is the code:

class ProgressAlertView: UIView {
    var title: String
    var steps: Int
    var messageLabels: [String]
    var errorLabel: String
    var successLabel: String

    public required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        alertLayout()
    }

    public override init(frame: CGRect) {
        super.init(frame: frame)
        alertLayout()
    }

    convenience init(title: String, steps: Int, messageLabels: [String], errorLabel: String, successLabel: String) {
        self.init(frame: frame)
        self.title = title
        self.steps = steps
        self.messageLabels = messageLabels
        self.errorLabel = errorLabel
        self.successLabel = successLabel
    }
}

This throws this error in both the required and override methods:

Property 'self.title' not initialized at super.init call

In an answer to a previous question someone explained that one needs to set the parameters first before calling the super.init(). When I try that, I get the following error messages (on top of the ones from above): 'self' used in property access 'title' before 'self.init' call

What's the correct way to do this?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
rantanplan
  • 243
  • 3
  • 17
  • The duplicate covers the code you posted. If you want help with the 2nd issue, post a new question with your code that causes the other error. – rmaddy Oct 23 '18 at 04:12
  • I've seen the other post but the answers aren't helpful as they don't all seem to suggest to change the order of assigning the properties, which is what I've described above will lead to another error. Will open new question. – rantanplan Oct 23 '18 at 19:39

0 Answers0