Failed to set (cornerRadius) user defined inspected property on (UIView)
Solution 1
The code is correct.
When you declare a @ IBDesignable
all the @IBInspectable
properties are exposed to the Interface Builder as User Defined Runtime Attributes.
The problem -
Unknown class MyClass in Interface Builder file
Is means that Interface Builder couldn't find some class. You have set wrong class that doesn't exist in your app.
Your customView class is MyView
but in the Interface Builder you have MyClass
Solution to fix-
- Set correct class in interface Builder, in your case
MyView
- Check Designable status. It should be Up to date , if it's not than something is wrong.
Also If you decided to remove customer Designable you should
- Remove custom class
- Remove User Defined Runtime Attributes
Solution 2
Based on the question title, a few people may come here with a slightly different problem (like I did). If you
- added an @IBInspectible
- and then deleted it in code
Then you may also get an error similar to
Failed to set (xxx) user defined inspected property on [Your Custom View] ...: this class is not key value coding-compliant for the key [xxx].
The solution is to delete the the old property.
Open the Identity inspector for your class, select the property name under User Defined Runtime Attributes, and press the minus button (-).
Again, this is not the answer to the OP's question, but it might be the answer to someone else's problem who comes here.
![E-Riddie](https://i.stack.imgur.com/jddpD.jpg?s=256&g=1)
E-Riddie
Electronic Engineer-turned-programmer (iOS Driven) StackOverflow and GitHub enthusiast Albanian currently living in Cologne, Germany. Contact me: LinkedIn Careers
Updated on May 15, 2020Comments
-
E-Riddie about 4 years
Details
I was watching the video of Session 411 on WWDC 2014 referring to "What's new on Interface Builder", and I was trying out how to create Frameworks in order to make
@IBDesignable
classes to preview my changes in Storyboard without having to run the application.@IBInspectable
properties are showing correctly when I add my class to a specific view and are rendering the view correctly with the below code:Code
@IBDesignable class MyView: UIView { @IBInspectable var borderColor: UIColor = UIColor.clearColor() { didSet { layer.borderColor = borderColor.CGColor } } @IBInspectable var borderWidth: CGFloat = 0 { didSet { layer.borderWidth = borderWidth } } @IBInspectable var cornerRadius: CGFloat = 0 { didSet { layer.cornerRadius = cornerRadius } } @IBInspectable var masksToBounds: Bool = false { didSet { layer.masksToBounds = masksToBounds } } }
Log
I noticed that these attributes were being added on User Defined Runtime Attributes (Under Identity Inspector). Now what I am expecting from this is when I run the code to keep these changed I made with a specific view.
I run the application and the view doesn't load the User Defined Runtime Attributes, and gives this error on output (not crash):
Unknown class MyClass in Interface Builder file Failed to set (cornerRadius) user defined inspected property on (UIView)
Question
What is causing the application not to load User Defined Runtime Attributes that I added under Identity Inspector?