Reputation: 426
I created a new Cocoa Touch Class (coding in Swift) and noticed that when others did they would have the code
init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
}
and then that if they did not also add the code
init(coder aDecoder: NSCoder!) {
super.init(coder: aDecoder)
}
it would not run. My code seemingly works Xcode6 Beta 3 without either. Can you explain what this does and whether or not I need it?
Upvotes: 0
Views: 194
Reputation: 4346
If your init functions simply call super.init, you do not need it. However, if you need to initialize some variables/lets in your class, you will need to supply an appropriate init function and call the super function when you are done.
Depending on what you are doing (using Storyboard, or NIBs, or manually creating views, etc), you will need to supply the appropriate init function.
Upvotes: 1