1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

StoryboardやXIB上で使うクラスのdelegateやprotocolがエラーになった場合の直し方

Last updated at Posted at 2017-04-12

Storyboard上で自作クラスを当てた際に、以下のようなエラーが出ていてプレビューができなかった原因と対処方法です。

IB Designables: Failed to update auto layout status: The agent crashed

原因・対策

StoryboardやXIB上で使う自作クラスがdelegateprotocolを持っていて、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)

参考になれば幸いです。

参考

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?