I have a very strange problem with XCode 7.1 interface builder. I have a really simple UIView subclass, which renders fine in storyboard editor:
import UIKit
@IBDesignable
class DashboardHeaderView: UIView {
@IBInspectable
var maskClipHeight: CGFloat = 40.0
override func layoutSubviews() {
super.layoutSubviews()
self.setMask()
}
private func setMask() {
let mask = CAShapeLayer()
mask.path = self.createMaskPath()
self.layer.mask = mask
}
private func createMaskPath() -> CGPath {
let maskPath = UIBezierPath()
maskPath.moveToPoint(CGPoint(x: bounds.minX, y: bounds.minY))
maskPath.addLineToPoint(CGPoint(x: bounds.maxX, y: bounds.minY))
maskPath.addLineToPoint(CGPoint(x: bounds.maxX, y: bounds.maxY - self.maskClipHeight))
maskPath.addLineToPoint(CGPoint(x: bounds.minX, y: bounds.maxY))
maskPath.closePath()
return maskPath.CGPath
}
}
However, if I only add initializer override to it:
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
It fails with errors:
- error: IB Designables: Failed to update auto layout status: The agent crashed
- error: IB Designables: Failed to render instance of DashboardHeaderView: The agent crashed
I am 100% certain that that initializer override makes it crash as I've reproduced it a couple of times. If I only comment it out, it works again.
Anyone has any idea why this is happening and if there is a way to fix/workaround it?