4

I'm using new Xcode 6 feature called "LiveRendering". As i need to use some inspectable properties a lot on different custom views, i want to declare them in protocols.

For example :

  • LiveRenderingTextAttributesProtocol (that declares inspectable properties for textColor, textSize
  • LiveRenderingBorderAttributesProtocol (that declares inspectable properties for borderStyle, borderColor, borderWidth)

etc ...

After that, each custom view implements the protocols it needs.

But i can't see my inspectable properties on InterfaceBuilder "Attributes inspector" column :/ The LiveRendering is working well when I define the values for these properties as "Used Defined Runtime Attributes", but i want to see them in my Attributes inspector column.

An idea to solve this problem please ?

QLag
  • 823
  • 1
  • 13
  • 33

1 Answers1

1

A protocol defines a set of optional or required methods and attributes to be compliant with, but it's the class the responsible for implementing them. To be able to have reusable base IBInspectable properties you could have a superclass like MyInspectableView that has those properties declared and implemented, so you can subclass it and have those IBInspectables shared between all of them.

Gorka
  • 331
  • 1
  • 5
  • Too bad :( In fact if i have 4 kinds of inspectable properties (text attributes (A), background attributes (B), border attributes (C), other attributes (D)), i need to create 15 superclasses to match all possibilities (A, B, C, D, AB, AC, AD, BC, BD etc ...) Not acceptable; so i will declare my properties directly on each custom views :/ – QLag Feb 11 '15 at 17:12
  • 1
    @QLag What you could do then is have a superclass implementing the setters for all inspectable properties you need, like text attributes, background attributes, etc. but not declaring them in the interface. Then subclasses can just declare the properties they want to use, and as they are child of that parent class, it all should just work. With this approach you wouldn't duplicate implementation, but just interface declarations. – Gorka Feb 11 '15 at 17:19