0

I recently began using Parse.com with swift and I am trying to create a simple app loading data into a table. In using the class PFQueryTableViewController, I found that the following code must be used:

override init!(style: UITableViewStyle, className: String!) {
    super.init(style: style, className: className)
}

required init(coder aDecoder: NSCoder) {
    super.init(coder: aDecoder)
    self.parseClassName = "MyClass"
    self.pullToRefreshEnabled = true
    self.paginationEnabled = true
    self.objectsPerPage = 50
}

My question is why must initialization of this class be called twice? and what are these initializations accomplishing?

Code was taken from this question: PFQueryTableViewController in Swift using Cloud Code function

Community
  • 1
  • 1
Mohammed B
  • 305
  • 1
  • 4
  • 14

1 Answers1

1

The initialization is not called twice; by defining two initializers you define two different ways to initialize an object. It's like with NSNumber:

  • init(float: Float)
  • init(double: Double)
  • init(bool: Bool)
  • and 13 more...

You use only one of them when initializing your NSNumber instance.


The requirement of init?(coder: NSCoder) is a different topic, discussed in the following questions:

Community
  • 1
  • 1
akashivskyy
  • 44,342
  • 16
  • 106
  • 116