I have custom IBDesignable
classes in swift that do some things that cause crashes in Interface Builder. Is there a flag I can check to see if I'm running in interface builder or not? Ideally it would be a precompiler directive (#ifdef COMPILED_FOR_INTERFACE_BUILDER
or something like that). I thought maybe I could set a flag myself in prepareForInterfaceBuilder()
but that seems messy and doesn't seem to work reliably as it looks class properties are set before that function is called and this can trigger code that causes problems. Seems like there must be a better way.
Thanks!
Asked
Active
Viewed 2,457 times
17

Sahil Kapoor
- 11,183
- 13
- 64
- 87

Michael John Ilardi
- 202
- 1
- 9
-
Don't know why this question was voted down. I think it's a great question. (Of course I have no useful answer...) – matt Jun 10 '15 at 00:35
-
I agree. This would be a very useful feature. (Voted) – Duncan C Jun 10 '15 at 00:56
1 Answers
24
You can use the preprocessor macro TARGET_INTERFACE_BUILDER to specify code for inclusion with or exclusion from your custom view class."

Ewan Mellor
- 6,747
- 1
- 24
- 39
-
Thanks! This was exactly what I was looking for and for some reason no amount of googling turned up that macro. Very useful! – Michael John Ilardi Jun 10 '15 at 07:34
-
-
2Wow, this is going to change my whole life dealing with IB crashes! Thank you x 1000! – disconnectionist Mar 07 '19 at 10:23
-