ios - IBDesignable from External Framework? -


i'd create custom views use @ibdesignable , @ibinspectable tags. have added these framework , linked framework test application. designables never show in storyboard.

how can use @ibdesignable , @ibinspectable create custom views external framework?

can use @ibdesignable , @ibinspectable in application non-embedded framework?

thank you.

i have found way use designables , inspectables cocoa touch frameworks. instructions below objective-c project , xcode 8 (i didn't test on older versions), , should identical if swift code involved.

since designables not discovered interface builder in frameworks, useless mark classes ib_designable in framework headers. interface builder discover designable classes when compiling project source files. idea therefore supply information framework companion source file, clients can compile project.

i discovered not have subclass mark framework class designable in project. can namely annotate each class must designable through category declared in companion .msource file, e.g.:

ib_designable @interface mycustomview (designable)  @end 

in fact, code not have compile, wrap within enclosing #if 0 ... #endif , still work. needed class somehow associated ib_designable attribute.

with information in mind, here how make designables work cocoa touch frameworks:


if framework vendor:

  1. if needed, have component must designable implement -prepareforinterfacebuilder
  2. add folder reference (blue folder) framework target, companion .m file in it. possible naming convention name folder designables , file within myframeworknamedesignables.m, can choose whatever most.
  3. in .m file, create category 1 above each view must designable. file must compilable client projects, means either need make necessary imports (e.g. framework global public header #import <myframework/myframework.h>) or use #if 0 ... #endif trick above

by enclosing file within blue folder, ensure folder copied in final .framework product, without companion source file being compiled. moreover, folder part of framework bundle, available clients of framework, whether integrate directly or using carthage.

if have demo project using framework target dependency, , if framework depends on other frameworks, run dlopen issues when trying render designable views in demo project. because ib_designable attributes discovered in framework target (since designables folder has been added it), xcode pre-builds in build/intermediates/ibdesignables derived data folder corresponding project. if @ content of folder, framework dependencies missing, leading dlopen issues.

to fix rendering in demo, add copy files phase framework target, add each required framework dependency file list, , set products directory destination. now, when xcode builds demo rendering, include dependencies well.


if user of framework designable support:

  • add framework (and framework dependencies, if any) embedded binary target
  • retrieve companion source file framework bundle , copy project, adding target. adding file located within framework or using symbolic link sadly not work, xcode not seem within frameworks @ all
  • add instance of designable view class (mycustomview in our example above) storyboard. interface builder should build project , render view

this solution not perfect since still have manually copy supplied source file, change between framework versions. works pretty well, though, , provides required within framework bundle itself.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -