我突然遇到了一个奇怪而可重复的错误,当使用@IBDesignable类时,@IBInspectable属性会给出以下警告:
明确一下,在Xcode中,这个警告只是一个问题,它可以正常打包。但仍然很烦人! 复现步骤:Main.storyboard: 警告:IB Designables:忽略用户定义的运行时属性键路径“test”,在“UIButton”的实例上。在尝试设置其值时遇到异常:[ setValue:forUndefinedKey:]:此类不符合键值编码规范的键测试。
- Create new project
Create a custom @IBDesignable UIButton subclass, with an @IBInspectable String property:
import UIKit @IBDesignable class TempButton: UIButton { @IBInspectable var test:String = "" }
- Drag a Button to a View Controller in the storyboard, and give it the custom class "TempButton" in the Identity Inspector.
- Now the 'Test' attribute should appear in the Attributes Inspector for 'Temp Button' properties - type anything into this field.
- Bam! The above warning appears. Remove the text from the field, and the warning disappears.
我尝试了几种解决方案 - 不同的变量名称,将“test”属性设置为可选项,使用初始化程序,但迄今为止都没有成功。
这是问题的屏幕截图: