I have a CustomClass.swift
and a CustomClass.xib
. I want XCode's Interface Builder to render views of class CustomClass
using the provided .xib-File. Just like it does when I run the app.
I am using XCode 8.3.2 (8E2002)
CustomClass.swift
import UIKit
@IBDesignable class forceInterface: UIView {
override init(frame: CGRect) {
super.init(frame: frame)
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
Bundle.main.loadNibNamed("forceInterface", owner: self, options: nil)
self.addSubview(view)
view.frame = self.bounds
}
@IBOutlet var view: UIView!
@IBOutlet weak var label: UILabel!
@IBOutlet weak var progressView: UIProgressView!
override func prepareForInterfaceBuilder() {
super.prepareForInterfaceBuilder()
}
}
CustomClass.xib
File owner is set to CustomClass
. It contains a UIView
that contains a UISwitch
and a UILabel
.
The problem is that, eventhough I have @IBDesignable
in my CustomClass.swift
, it isn't rendering in the InterfaceBuilder. I am placing a UIView
there and setting its class to CustomClass
:
As you can see, it even says Designables: Up to date in the inspector. But I am not seeing anything.
When running the app everything works as expected!