Unfortunately it isn't possible to use IBDesignables
with static libraries (or static frameworks).
This isn't a great answer but I want to give some context on why.
It seems that the way Interface Builder loads classes to be shown as designables is by actually dynamically loading the dynamic framework that you create (and not your app's binary), and using the classes directly (after changing them using the Objective-C runtime quite a bit).
You can see that Interface Builder isn't loading your app, and just the individual frameworks with these steps:
- Create a new Xcode project
- Create a new framework target in the project
- Add a class that is
IBDesignable
- In the storyboard from your app create a view and set its class to your framework's
IBDesignable
class
- Click "Refresh All Views" in the "Editor" menu
- In your DerivedData folder for the project, in the
IBDesignables
directory, you can see that only your framework target has been built.
Interface builder actually loads your framework using dlopen
manually. You can also see that to facilitate this when building your framework, Interface Builder actually adds 2 RPATH
s to your binary, so the dependencies can be found in the custom paths (you can view this with otool -L frameworkbinary
). This method of loading your binary isn't possible with static libraries.
For what it's worth I think the best workaround for this is to build dynamic frameworks, instead of static libraries, but only for IBDesignable
builds. You'll have to do some configuration work to do this, and it isn't easy to work around Xcode to have this work, but if you try it, you can use either the build path, or the environment, to differentiate IBDesignable
builds vs "normal" builds.