IB_DESIGNABLE, IBInspectable -- Interface builder does not update
Asked Answered
K

11

96

I have the following set of code:

CustomView.h

#import <UIKit/UIKit.h>

IB_DESIGNABLE
@interface CustomView : UIView

@property (nonatomic) IBInspectable UIColor *borderColor;
@property (nonatomic) IBInspectable CGFloat borderWidth;
@property (nonatomic) IBInspectable CGFloat cornerRadius;

@end

CustomView.m

#import "CustomView.h"

@implementation CustomView

- (void)setBorderColor:(UIColor *)borderColor {
    _borderColor = borderColor;
    self.layer.borderColor = borderColor.CGColor;
}

- (void)setBorderWidth:(CGFloat)borderWidth {
    _borderWidth = borderWidth;
    self.layer.borderWidth = borderWidth;
}

- (void)setCornerRadius:(CGFloat)cornerRadius {
    _cornerRadius = cornerRadius;
    self.layer.cornerRadius = cornerRadius;
}

@end

(For Swift reference, this problem was also occurring with Swift code)

CustomView.swift

@IBDesignable
class CustomView : UIView {
    override init(frame: CGRect) {
        super.init(frame: frame)
    }

    required init(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }

    @IBInspectable var borderColor : UIColor = UIColor.clearColor() {
        didSet {
            self.layer.borderColor = borderColor.CGColor
        }
    }

    @IBInspectable var borderWidth : CGFloat = 0.0 {
        didSet {
            self.layer.borderWidth = borderWidth
        }
    }

    @IBInspectable var cornerRadius : CGFloat = 0.0 {
        didSet {
            self.layer.cornerRadius = cornerRadius
        }
    }
}

I added a UIView to a view controller on the storyboard and set its subclass to CustomView.

enter image description here

This adds the "Designables" row. It is stuck on "Updating" and the tooltip says "Waiting for Target to Build". It never changes from this status.

When I move to the attributes inspect, I am able to set these IBInspectable properties:

enter image description here

And once set, they also show up in the "User Defined Runtime Attributes":

enter image description here

However, the "Designables" status never moves beyond "Updating" with still the same tooltip (I've tried Cmd+B building several times, nothing changes).

Moreover, as I set the IBInspectable properties, I get a warning for each one:

IBDesignables - Ignoring user defined runtime attribute for key path "borderColor" on instance of "UIView" ... this class is not key-value coding-compliant for the key borderColor.

Screenshot of the warnings generated:

enter image description here


I am familiar with the key-value coding-compliant issues and generally know how to solve them... but I don't understand how to solve this issue here. According to the view's identity inspector, the view is a "CustomView" (not a regular "UIView", which doesn't have these properties). And if the view weren't a "CustomView" then these designable properties wouldn't show up in the Attributes Inspector, right? But when Interface Builder tries to apply these attributes to the view, it goes back to thinking the view's class is "UIView" and cannot apply the attributes.

Any help? Please let me know if I've left out some important detail, but for what it's worth, I followed this tutorial exactly (other than ObjC vs Swift). It's also worth noting that I followed this tutorial exactly on another machine and it worked like a charm (I intended to make this post last night but the computer I was on then didn't have this issue).


Based on comments, it has been suggest that perhaps the .m file isn't included and that might be causing the problem. I thought surely I would have gone out of my way for this scenario to be the case, but I checked anyway.

enter image description here

When I first started attempting to do this, I was under the understanding that the IB_DESIGNABLE classes had to be part of a different UIKit framework. So from this first screenshot, you can see that I set up a "CustomViews" framework, which has one class, CustomView. You'll also see here that I also created a OtherView, which is identical to CustomView, except it's not in a separate framework. The identical problem persists on the storyboard between both classes however.

Here we have a screenshot indicating that CustomView.m is included to be built with the CustomViews framework:

enter image description here

Meanwhile, the following screenshot indicates several things:

  • CustomViews.framework is appropriately included in the main project.
  • OtherView.m is also included as a compile source, so even if something is wrong with CustomView, OtherView should work, however it generates identical errors.
  • Main.storyboard and LaunchScreen.xib are showing up as red. I have no idea why, and haven't the slightest clue as to why LaunchScreen.xib should (I haven't touched this file), though I can say after looking at other projects, Main.storyboard also shows up in red for those projects, and I'm not doing anything with IB_DESIGNABLE or IBInspectable there.

enter image description here


I have tried and retried this several times now. It works every time on my computer at home--I can not reproduce the problem described in this question at home. At work, it never works. The problem described in this question happens every time.

Both computers are Mac Minis purchased new this year (not the new models, late 2012 model). Both computers are running OS X Yosemite 10.10. Both computers are running Xcode Version 6.1. At home, the build is (6A1052d). This morning, I can confirm that both computers are running identical builds of Xcode.

Others have suggested to me that it might be bad RAM. That seems far fetched to me. I've restarted the project multiple times, restarted the computer multiple times. Seems to me if there were bad RAM on a computer approximately 6 months old, that I'd be seeing other problems, and that this problem would be less consistent. But this exact problem persists despite numerous times restarting the entire project from scratch and full restarts on the computer.


It should be worth noting that if I actually compile and run this project, the custom view with the IBInspectable properties actually displays as I expect the storyboard to display it. I imagine that this would be the case even with out the IB_DESIGNABLE and IBInspectable directives however, as these are created as User Defined Runtime Attributes.

Kierstenkieselguhr answered 31/10, 2014 at 11:53 Comment(4)
Well, it was just an idea. I removed CustomView.m from the target and then got similar warnings when running the app.Mike
That seems like a real gremlin given your comparison to a seemingly identical machine (which differs somehow). Have you tried posting to devforums? It seems like you're flying blind without additional information, and your process seems reasoned and rational. The "build" warning may not mean too much as Xcode is rife with misleading error messages. For kicks though, you have tried Editor->"debug selected view", right? (Probably won't work, but worth a sanity check). Also, does anything show up in the (logging) Console app?Sourdough
Am having the same problem. Mines with a single xib file containing an IB_DESIGNABLE. However checking my setup, I already have the automatic refreshing on and I've now tried manual refreshes, clearing the derived data first, etc. So far nothing nothing has worked. The weird thing is that I had this control working fine, then it stopped. And I don't think I changed any code in between. Crazy.Picky
Was showing warnings as per above. Have now created a second class with the code copied from the original IB designable. This class works perfectly and when I switched back to the original non-working class, it now works fine. From this I've concluded that there is some cache somewhere (not in derived data) that is not cleared until the original ib designable is swapped for another ib designable. Changing to a UIView doesn't seem to clear this cache. Only another ib designable. Go figure :-)Picky
K
79

Based on chrisco's suggestion to debug the selected view (which I had already done, but went to try again for good measure), I noticed a couple of other options at the bottom of the Editor menu.

  • Automatically Refresh Views
  • Refresh All Views

I clicked "Refresh All Views" and after Xcode had a bit of a think, suddenly the storyboard was displaying my view as expected (properly applying my IBInspectable properties).

enter image description here

I then went through the whole process again to confirm that this is the solution.

I created a new class, ThirdView. This class is identical to the others, again. I changed my view's class to ThirdView and got something slightly different this time:

enter image description here

Clicking "Show" to me to the warnings:

enter image description here

A new one this time:

Using class UIView for object with custom class because the class ThirdView does not exist.

This isn't really any more helpful than what already existed. Plus, now the other three warnings have doubled into 6 strangely.

Anyway, if I click "Refresh All Views" from the Editor drop down menu again, all the errors go away, and once again, the view properly displays.

Still, up to this point, everything I did was stuff I never messed with at home. At home, it just worked. So I turned on "Automatically Refresh Views" and created a "FourthView" to test--once again, identical to the first three.

After changing the view's class to "FourthView" the designables label said "Updating" for a short moment then finally said "Up to date":

enter image description here

So, I checked my computer at home. "Automatically Refresh Views" is turned on at the computer that was always working. It was turned off at the computer that wasn't. I don't ever remember touching this menu option. I can't even tell you for sure whether it existed before Xcode 6. But this option is what was making the difference.


TL;DR, if you're having the same problem described in the question, make sure "Automatically Refresh Views" is turned on (or manually "Refresh All Views" when you need an update in IB):

enter image description here

Kierstenkieselguhr answered 3/11, 2014 at 18:36 Comment(2)
I was actually looking for how to turn it off as it keeps rendering in the background making older MacBooks really slow. Thanks!Deferential
This may resolve temporary, but check out the answer from @Martin-Gilles LavoieDioptometer
S
23

Just a quick hint for anyone else having this problem: remember to specify the type of the variable.

// Doesn't show up in IB
@IBInspectable var includeLeftSection = true

// Shows now that it knows the type
@IBInspectable var includeLeftSection : Bool = true
Spiller answered 27/9, 2016 at 21:7 Comment(0)
B
22

I have a few more details that may cause your IBDesignable classes to not be loaded.

Select your problematic storyboard/xib where your custom views ought to display.

In the navigator area, head to the Report Navigator in your XCode workspace/project.

In the Editor menu of XCode, hit (as mentioned by nhgrif), the "Refresh All Views" option. This will cause IB to launch a compile for a whole bunch of stuff that you, I'm certain, would not expect.

In the Report Navigator, Click on "By Group" to filter content and look at the "Interface Builder" section. You will see that for the sake of loading the custom IBDesignable views framework, it will compile LOTS of things. If any of these targets do NOT compile, such as (perhaps deprecated) unit test targets (even if they are totally unrelated to the code that loads these views or storyboard), then IB will fail at loading your dll.

In my case, IB tried to compile 8 targets, including 4 that where unit tests that had not been updated since recent refactoring changes we've been working on.

Most of the code changes/fixes I have done in order for IB to properly load and display my customs views where not related or even linked against these classes, nor would it ever load the storyboard in the course of running these unit tests. Yet, IB had a dependency on the whole workspace compiling for it to work.

Bullhorn answered 17/6, 2015 at 21:52 Comment(5)
Hey, so how do I stop IB from trying to load and display views not related or linked to these classes?Kekkonen
I'm assuming it has to do with header dependencies. Wether the designable classes are touching other classes, the moment the header is seen it will build those related implementations. Apple is toying with the source dependency graph code in XC7GM which utterly fails on our project with XCode crashing when it's building the graph. The following 7.1betas dont exhibit the issue. Our automated build system is still dependant on 6.4 for the moment so we've not investigated how to resolve this further under XC6.4. We'll be jumping straight to 7.1GM.Bullhorn
If you've got multiple targets / projects then this is absolutely the right answer and really does fix the problem - ALL targets must build cleanly, I didn't even know there was an "Interface Builder" section in the report navigator! All the other answers I've seen are basically a lot of hand waving that might fix it temporarily, but this is the definitive solution. Well done.Dioptometer
So, according to this, we can conclude that IB_DESIGNABLE attribute is a total shit and waste of time. Just avoid using it.Motorist
IB_DESIGNABLE has nothing to do with the issue and solution listed above. It's merely a NO-OP flag for IB to spot usable things. You just need to maintain a clean house.Bullhorn
P
6

I had the same warning Ignoring user defined runtime attribute for key path .. even though I am absolutely sure I didn't do anything wrong with my custom IBDesignable view class.

Turned out, in my case, it got to do with Xcode cache.

rm -rf ~/Library/Developer/Xcode/DerivedData/*

Purge DerivedData and the warning is gone.

Pulchritudinous answered 18/11, 2015 at 13:10 Comment(3)
Shortcut in XCode for achieving the same result: ⌘⇧KCapsulate
@Capsulate I believe Clean Build is different from purging DerivedData folder. Of course, sometime clean build is good enough to solve certain Xcode caching problems.Pulchritudinous
@Capsulate you probably meant ⌘⌥⇧K (cmd+alt+shift+K)Externality
R
5

Incase any one else comes up against the error IB Designables class does not exist, for the same reason as I did. Top answer was not my issue... but here is a slightly related problem...

There is a property hidden in the story board source code called customModule.

For example I had a class called ForwardArrow inside a separate framework that I accidentally added to my main target.

So the XML for some views ended up as customClass="ForwardArrow" customModule="MainTargetNameWasHere"

When I removed them from the main target in the build the story board did not update MainTargetNameWasHere to CustomViews which is the framework where it was located and started giving that no class found error.

So TLDR; Make sure that if your IBDesignable is in another framework that the customModule xml attribute in your story board is set to the right value. And if it isn't there at all add it.

Example from my source:

<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="MUG-jc-2Ml" customClass="ForwardArrow" customModule="CustomViews">
Rotman answered 17/7, 2015 at 21:32 Comment(1)
Holy crap, this has been driving me nuts for a day. What a nasty little bug.Spiller
S
5

As my example, I was using CheckboxButton via pod and the graphics of checkbox never shows up in the storyboard while I got the same issues described in the question here:

warning: IB Designables: Using class UIView for object with custom class because the class CheckboxButton does not exist

and

warning: IB Designables: Ignoring user defined runtime attribute for key path "checkColor" on instance of "UIView". Hit an exception when attempting to set its value: [ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key checkColor.

The way solved my problem was to supply the module with name CheckboxButton as below:

Note: you should replace CheckboxButton to whatever the name of module you are using.

Stcyr answered 2/10, 2016 at 6:17 Comment(0)
K
4

I personally solved this problem by using the "-" button to delete content from my identity inspector. When you remove custom classes, change content in the IB and then add a new custom class, the designable elements in the identity inspector don't get removed and it caused me to have that error. Just Delete everything and rebuild. enter image description here

Kekkonen answered 16/10, 2015 at 8:49 Comment(3)
I did exactly what you said and it solved my problem. All the previous solutions exposed here didn't make it. Thanks a lot. ;o)Whittier
@Whittier sometimes it's the answers no one looks at that solves it, eh? :)Kekkonen
I had an issue where I renamed an IBInspectable property on a few of my xib's. After doing that I had a ton of warnings informing me that XCode couldn't find the now renamed property. Removing the property from the identity inspector fixed my issue.Dineric
C
1

I know this is answered, but here is one more experience.

I was having some problems unrelated to this issue, but in the process I removed @IBInspectable from the vars in my class and deleted the attributes from the identity inspector (alt-apple-3).

After fixing the (code) issue with the component, I refreshed everything a ton of times, but still no attributes in the identity inspector.

Eventually, I noticed that they were back, but only in the attributes inspector (alt-apple-4). As soon as I added values to them there, they re-appeared in the identity inspector

Cecillececily answered 12/3, 2016 at 14:29 Comment(0)
I
1

Dave Thomas's answer above gave me the (reverse) solution when not of the others (Derived Data, Editor > Refresh) did, but for the sake of clarity in case people aren't sure where to edit the XML... you don't need to!

  1. In your storyboard file select the troublesome view
  2. On the right-hand sidebar select the Identity Inspector tab (3rd option from the left).
  3. You'll have your custom class, which should already be set, and the Module. For me this was empty, and I was getting the same errors as OP. I set the Module to my project name and BAM - it started working after rebuilding!
Insomnolence answered 23/4, 2016 at 15:49 Comment(0)
G
0

I just went through the ringer on this problem. I tried all the things listed here and elsewhere without any luck. This is a storyboard that worked fine forever and it suddenly stopped working with the "Ignoring user-defined runtime attribute..." problem.

For whatever reason, removing this code from one of my IBDesignable's fixed it:

-(void)viewDidLoad {
    self.clipsToBounds = YES;
}

removing this caused all the warnings to go away, even in other IBDesignable objects. I have no idea why this one step fixed it, but maybe it will help someone else too.

Gracia answered 24/2, 2016 at 22:43 Comment(1)
you missing call to supper hereDesperado
W
0

I was having the same problem and I had to change the cornerRadius and BorderWidth to be a String and then cast it to CGFloat, it was the only solution for me to be able to change the values and see the changes in interface builder.

@IBInspectable var borderColor: UIColor? {
    didSet {
        layer.borderColor = borderColor!.CGColor
    }
}

@IBInspectable var borderWidth: String? {
    didSet {
        layer.borderWidth = CGFloat(Int(borderWidth!) ?? 0)
    }
}

@IBInspectable var cornerRadius: String? {
    didSet {
        layer.cornerRadius = CGFloat(Int(cornerRadius!) ?? 0)
        layer.masksToBounds = layer.cornerRadius > 0
    }
}
Windowsill answered 11/5, 2016 at 13:55 Comment(1)
I think IBInspectable can only do certain types, so maybe you would have needed to use Float instead of CGFloat and cast that insteadGlister

© 2022 - 2024 — McMap. All rights reserved.