Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift, super.init() Must call a designated initializer of the superclass 'UIView' error [duplicate]

Tags:

I am new with Swift. I inherited a project. I saw it running on a device. However, when I checkout the code and it had many errors. I was able to clear out the errors. However, I run into this one that is baffling me. The project uses xib files as well. Here is the code.

    required init(coder aDecoder: NSCoder) {         super.init(coder: aDecoder)     }      override init(frame: CGRect) {         super.init(frame: frame)     }     init(items:NSArray, viewController:AnyObject){         super.init()         //itemsArray = items         itemsArray = items as [AnyObject]         //commonInit(viewController as UIViewController)         commonInit(viewController as! UIViewController)     } 

I get the error under the init(items:NSArray, viewController:AnyObject) method/function. The error is pointed at the "super.init()". It states "Must call a designated initializer of the superclass 'UIView' error"

I been searching, googling, asking others and nothing has turned up. Can I get help on fixing this error, or at least why this error happens? I would like understand so I can become a better software developer.

Edit: I would like to thank everyone for their insight and help. I found out the problem is bigger. I did the changes suggested in the super.init(frame: CGRect). I had to change an array property as well which was affecting the init function.

like image 629
EberronBruce Avatar asked Jun 17 '15 09:06

EberronBruce


1 Answers

As the error message suggests you can only call the designated initializer of the superclass.

To solve this you need to call : super.init(frame: frame) instead of super.init()

like image 190
The Tom Avatar answered Sep 28 '22 07:09

The Tom