IBDesignables Render only when File Changes

I'm seeing a strange issue in which my @IBDesignable class fail to render in Interface Builder unless I make a change to the underlying class file. To elaborate on what I mean by that,

  1. Create a subclass of UIButton and mark the class as @IBDesignable
  2. Add some @IBInspectable properties.
  3. Switch over to Interface Builder, go to the Library and drag an instance of a Button onto your Interface Builder canvas.
  4. Go to the Identity Inspector and change the class type from UIButton to your custom UIButton subclass.
  5. Go back to the Attributes Inspector.

At this point, I do see all my @IBInspectable properties in the Attributes Inspector, and Interface Builder properly puts my custom class name above my defined inspectable properties.

Everything looks normal except for the fact that the UI above my Inspectable that typically reads "Designables Up to date" does not show at all.

I then proceed to change and modify the Inspectable properties only to see that the button in the canvas does not update or change at all.

At this point, I go back to my class file, and make a modification. Any modification at all, even just adding a single space to a comment, and when I go back to Interface Builder, everything is working.

I see the "Designables Up to date" UI showing, my button is displaying with my custom styling, etc. If I interact with, and make changes to my Inspectable properties in the Attributes Inspector, my button also properly updates in real time.

While an annoyance during the development process, I do see this becoming a bit of more significant issue given the fact that the components I am building into a Framework are to be distributed to 3rd party developers in the form of XCFramework binary in a Swift Package. A third party developer won't be able to say, go to the class file and make a modification, nor would I want them to.

The only other work around I found is after changing the class type to your custom @IBDesignable class, to then just quit and reboot Xcode. And when after relaunching the @IBDesignable appears and works correctly.

Obviously, I don't want to add to my documentation to reboot Xcode after dragging a UI component to your canvas.

I've never seen this issue before, has anyone else seen anything like this? I am currently running Xcode 13.4.1 (13F100), still haven't had a chance to update to the latest Xcode. I will also try upgrading later this afternoon to the latest Xcode 14 release but I'm not seeing anything in the Release Notes that might indicate anything that would address this issue if it had been previously identified.

Answered by JohnC2 in 733831022

Just a update, I am seeing the same issue in Version 14.0.1 (14A400).

And while my attributes appear in Attributes Inspector, it also appears when clicking on the view and going to the Editor menu that the "Debug selected views" menu item is disabled.

Accepted Answer

Just a update, I am seeing the same issue in Version 14.0.1 (14A400).

And while my attributes appear in Attributes Inspector, it also appears when clicking on the view and going to the Editor menu that the "Debug selected views" menu item is disabled.

Not sure why the above reply was marked as "Accepted". Perhaps I clicked something on accident, but there appears to be no way to undo that or edit any existing posts on these forums. Very frustrating.

Some more findings, if I change the class type to that of my Designable, and then right click on my Storyboard and choose Open As > Source Code and then right clicking on the Storyboard once again and selecting Open As > Interface Builder - Storyboard the IBDesignable begins rendering properly.

Whats strange though is if open the storyboard into a tab or window in Xcode, close that window or tab and re-open the Storyboard, that doesn't work.

But if I view the Storyboard as source code, then toggle back, it works. Clearly some sort of a bug.

I suppose at this point I need to write a note in my documentation containing instructions documenting this workaround to developers using my UI component. Because if I file a Radar with a sample project containing my code, it'll just sit in Radar for years and years, along with all my other Zombie Radars that have just been sitting there.

I still haven't had time to create a sample project for a Radar, I will try to get to it this week. I will post the Radar number here when I file it. Seems like I'm hitting a strange edge case because I am not seeing the issue outlined above with another one of my IBDesignable views.

I think I will also need to file a Radar on the ability to remove a post that was accidentally marked as "Accepted". Seems like others have been having the same issue for quite some time per this post. https://developer.apple.com/forums/thread/662659

IBDesignables Render only when File Changes
 
 
Q