IBInspectable stored property in extension

49 Views Asked by At

I would like all subclasses of UIView to have a stored property IBInspectable. Unfortunately I can't use an extension of UIView, because in an extension, an IBInspectable cannot be a stored property.

The best solution I have right now is to create base sublcasses of all my UIViews (BaseUIView, BaseUILabel, BaseUIImageView, etc.), place the same IBInspectable in all of those, and have all my views be one of the base classes.

I'm not crazy about this solution.. .it's a little messy, and the list of base classes will probably need to be continually be updated. Does anyone know a better solution?

1

There are 1 best solutions below

2
OneCommentMan On

Personal I would avoid using IBInspectable, they are nothing but trouble. Can cause Storyboards to crash or take forever to load/lag.

What I would do is brake down consistent styles into class components and do all the styling there. There are other ways you can do this, all have their pro/cons. But do yourself a favour and keep away from IBInspectable.