I am trying to use IBInspectable
to add borders to my views.
extension UIView {
private func getBorder(integer: Int) -> UIRectEdge {
You have an infinite recursion there, that is causing the crash. Basically within the setter of borderColor
you're calling the setter for the same property, resulting the infinite recursion.
This happens because class extensions are not allowed to have stored properties, so Swift doesn't generate a backstore for your property, instead it treats it like a computed property, and calls the setter whenever you try to set the property.
There are two solutions that I can think of at this time, that will solve your problem:
UIView
accessors (objc_setAssociatedObject()
/ objc_getAssociatedObject()
) instead of direct iVar reference. You will not need to subclass and to update your xibs, however this solution is a little bit messier than the first one.