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,
- Create a subclass of
UIButton
and mark the class as@IBDesignable
- Add some
@IBInspectable
properties. - Switch over to Interface Builder, go to the Library and drag an instance of a Button onto your Interface Builder canvas.
- Go to the Identity Inspector and change the class type from
UIButton
to your customUIButton
subclass. - 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.