UIView init with coder causes a recursion

Turn's out what I have done wrong is how I prepared the .xib file, I've set the View itself, instead of the file owner to TestUIView class. After changing the file owner(and reseting the constraints), everything worked fine.


For future seekers....

Brief : The recursive call of required init?(coder aDecoder: NSCoder) occurs when you accidentally set your custom view class in identity inspector of your ContentView.

When the compiler tries to load your Nib file(the owner view) it first needs to initiate your ContentView (see the following picture) and if you have mistakenly set the custom class for your ContentView or any of its subviews, it goes through another Nib loading process and stuck in a recursive infinite loop.

To do it the right way, you should only set your custom view class for the view in Placeholder’s part. Please see 1 and 2 in the following picture.

In this picture I have defined a custom class named CardView.

enter image description here

Tags:

Ios

Uiview

Swift