Set text attributes via UIAppearance in a custom UIView subclass in Swift
<p>Accoding to <a href="http://nshipster.com/uiappearance/" rel="noreferrer">NSHipster</a>, "having custom UI classes conform to UIAppearance is not only a best-practice, but it demonstrates a certain level of care being put into its implementation."</p>

<p>Therefore, I'm trying to set text attributes, which are later used to create a <code>NSAttributedString</code>, to a property <code>var titleTextAttributes: [String : AnyObject]?</code> in a <code>UIView</code> subclass like this:</p>

<pre><code>func applyAppearance() {

    UINavigationBar.appearance().translucent = true
    UINavigationBar.appearance().tintColor = UIColor(named: .NavBarTextColor)
    UINavigationBar.appearance().barTintColor = UIColor(named: .NavBarBlue)
    UINavigationBar.appearance().titleTextAttributes = [
        NSForegroundColorAttributeName: UIColor(named: .NavBarTextColor),
        NSFontAttributeName: UIFont.navBarTitleFont()!
    ]

    ActionBarView.appearance().backgroundColor = UIColor(white: 1, alpha: 0.15)
    ActionBarView.appearance().titleTextAttributes = [
        NSKernAttributeName: 1.29,
        NSFontAttributeName: UIFont.buttonFont()!,
        NSForegroundColorAttributeName: UIColor.whiteColor(),
    ]
}
</code></pre>

<p>This is a snipped from my <code>AppDelegate</code>.</p>

<p>Now, when trying to set <code>ActionBarView.appearance().titleTextAttributes = [ ... ]</code>, I'm getting the following runtime error:</p>

<p><a href="https://i.stack.imgur.com/qRHan.png" rel="noreferrer"><img src="https://i.stack.imgur.com/qRHan.png" alt="error when trying to set text attirbutes on a custom uiview subclass"></a></p>

<p>What's worth mentioning is that setting the attributes on <code>UINavigationBar</code> works without any problems.</p>

<p>Going to <code>UINavigationBar</code>'s header file reveals this:</p>

<pre><code>/* You may specify the font, text color, and shadow properties for the title in the text attributes dictionary, using the keys found in NSAttributedString.h.
 */
@available(iOS 5.0, *)
public var titleTextAttributes: [String : AnyObject]?
</code></pre>

<p>Which is exactly the same definition of a property as in my <code>ActionBarView</code> class:</p>

<pre><code>class ActionBarView: UIView {

    var titleTextAttributes: [String : AnyObject]?

    // ...
}
</code></pre>

<p>So my question is: Is there anything I can do to implement a property with a dictionary of text attributes in my own UIView subclass that can be set via <code>UIAppearance</code> proxy? <strong>Since using <code>UI_APPEARANCE_SELECTOR</code> is not possible in Swift?</strong> And why is it working out-of-the-box for UIKit classes like <code>UINavigationBar</code>? Is there some kind of black magic involved?</p>