TIMEX TIMEX - 6 months ago 18
iOS Question

How can I subclass UIView?

class ReplyContent: UIView {
var body: String?
var image: UIImage?

convenience init(body: String?, image: UIImage?){
self.body = body
self.image = image
self.init()
}

required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

}


The error states: "Cannot invoke ReplyContent.init with no arguments.

Answer

You can't just do UIView.init() with no arguments. You need UIView.init(frame:) or UIView.init(coder:).

Comments