はじめに
Xcode6から追加されたInterfaceBuilder(以下IB)の機能であるIBDesignableとIBInspectableを使ってみて、ハマったエラーがあったので共有したいと思います。
IBDesignableとIBInspectableについては
などの記事が詳しく書かれているので参考にしてください。
エラー内容
Failed to set (myKey) user defined inspected property on (MyApp.MyClass):
[<MyApp.MyClass 0x7fc1315478c0> setValue:forUndefinedKey:]:
this class is not key value coding-compliant for the key myKey.
this class is not key value coding-compliant for the key myKey.
のエラーについては、関連付けされたプロパティを編集・削除した際に、ストーリボードに古い関連が残っているエラーがほとんどだと思います。
この場合は、ストーリボード上から古い関連付けされたプロパティなどを削除してあげれば解決できます。
今回のは、Failed to set (myKey) user defined inspected property on(MyApp.MyClass):
のエラーでIBInspectableのプロパティのエラーです。
警告の部分では以下のメッセージが
~/Main.storyboard: warning: IB Designables:
Ignoring user defined runtime attribute for key path "myKey" on instance of "MyApp.Myclass".
Hit an exception when attempting to set its value: [<MyApp.Myclass 0x7fb51b0104c0> setValue:forUndefinedKey:]:
this class is not key value coding-compliant for the key myKey.
解決策
このエラーの解決法は場合によって異なると思いますが、自分の場合だとアクセスコントロールがprivate
になっていることが原因でした。
@IBInspectable private var myKey: Int {
didSet {
}
}
普通に考えたらごくごく当たり前のことなのですが、IBInspectableのプロパティをprivate
で設定しても、IBでは普通に値が設定できてしまうんですよね。ってことで簡単な問題に気付かず試行錯誤してました。

普通にアクセスレベルを修正したら問題なく動作しました。
アクセスレベルはpublic
かinternal
であれば問題ないです
(明示的にアクセスレベルを指定しなければ、自動的にinternal
になる)
@IBInspectable var myKey: Int {
didSet {
}
}