in objective c it can be done in init method by
-(id)init{
self = [[[NSBundle mainBundle] loadNibNamed:@"ViewBtnWishList" owner:0 options:nil] objectAtIndex:0];
return self;
}
but when i do this in swift
init(frame: CGRect) {
self = NSBundle.mainBundle().loadNibNamed("ViewDetailMenu", owner: 0, options: nil)[0] as? UIView
}
cannot assign to self in a method error is shown. now my approach is to create a view, and add the view loaded from nib to it. anyone have a better idea?
I think this is the easies but also the cleanest way to assign a xib to a UIView. Xcode 7.3 and swift 2.0.
The true Swift approach is the use of protocols and protocol extensions.
the implementation of our protocol is now complete
In order for this protocol to work, you need the name of our xib file and the class were the same. For example, for example
finally add the protocol and make your class "final", like here.
That's it