2

I have custom UI element designed with a help of IBInspectables, so that I can use and modify it in the Interface Builder. There are 2 inspectables which effectively change the same property of the element but in a slightly different manner.

enter image description here

At the screenshot there is title that sets the title of the element, and locTitleKey that gets NSLocalizedString by the key and sets it as the title.

As I can see from passing different values to these inspectables:

  1. If locTitleKey is specified, and title is left empty, the localised string is used
  2. If both are specified, title is used and localized one is ignored

The question - is that behaviour predictable?

In other words, can I safely assume that the order of evaluation of my IBInspectables always be the same? (title and then locTitleKey)

To provide more context here are the snippets of code used.

title is defined in the scope of the class itself:

@IBDesignable
class StandardInputField: UIView, NibLoadable {
    //...
    @IBInspectable
    public var title: String? {
        didSet {
            titleLabel.text = title
        }
    }
    //...
}

And locTitleKey is defined as extension:

extension StandardInputField {
    @IBInspectable var locTitleKey: String? {
        get {
            return nil
        }
        set(key) {
            title = key?.localized
        }
    }
}
markvasiv
  • 522
  • 2
  • 16

0 Answers0