Storyboard上で自作クラスを当てた際に、以下のようなエラーが出ていてプレビューができなかった原因と対処方法です。
IB Designables: Failed to update auto layout status: The agent crashed
原因・対策
StoryboardやXIB上で使う自作クラスがdelegateやprotocolを持っていて、IBOutletで繋ぐ場合はクラス定義をAny等にしておく必要があります。
protocol MyDelegate {
func somehing()
}
class MyButton: UIButton {
var delegate: MyDelegate?
}
protocol MyDelegate {
func somehing()
}
class MyButton: UIButton {
var delegate: AnyObject?
}
Interface Builderから使う際の型定義については、Appleのドキュメントにも書かれています。
Interface Builder does not support connecting to an outlet in a Swift file when the outlet type is a protocol.
Declare the outlet type as AnyObject or NSObject, connect objects to the outlet using Interface Builder, then change the outlet type back to the protocol. (17023935)
参考になれば幸いです。