The "self.title" property is not initialized when super.init is called in swift

I have a class derived from UIView, but I always initialized it, showing that the error says: "The property" self.title "is not initialized when super.init was called in swift"

Here is my code

class A: UIView
{

var title : String
var recordUrl : String
var content : String

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

init(frame :  CGRect ,title : String, recordUrl : String  , content : String)
{
    super.init(frame: frame)

    self.title = title
    self.recordUrl = recordUrl
    self.content = content
}
}
+4
source share
1 answer
init(frame :  CGRect ,title : String, recordUrl : String  , content : String) {
    self.title = title
    self.recordUrl = recordUrl
    self.content = content
    super.init(frame: frame)
 }

In swift, you must first initialize your parameter and then implement super.Method ()

+5
source

All Articles