6

I have a class derived from UIView , but i initialized it always show the error says "Property 'self.title' not initialized at super.init call 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
}
}
Dean Lee
  • 781
  • 2
  • 7
  • 13

1 Answers1

12
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 should init your parameter first, and then implement super.Method()

Kim Jin
  • 180
  • 1
  • 8