How to convert a String to UIColor in Swift 3.0?
<p>I am trying to convert an existing program which uses a list of predefined colors from Objective-C to Swift.
The original code used Selector to extract a <code>UIColor</code> based on it name represented as a <code>NSString</code></p>

<pre><code>#define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue &amp; 0xFF0000) &gt;&gt; 16))/255.0 green:((float)((rgbValue &amp; 0xFF00) &gt;&gt; 8))/255.0 blue:((float)(rgbValue &amp; 0xFF))/255.0 alpha:1.0]

-(UIColor *)getColor:(NSString*)colorName
{
    SEL selColor = NSSelectorFromString(colorName);
    NSString *errorMessage = [NSString stringWithFormat:@"Invalid color name: %@ !!!", colorName];
    NSAssert([UIColor respondsToSelector:selColor] == YES, errorMessage);
    UIColor *mycolor = [UIColor performSelector:selColor];
    return mycolor;
}

+ (instancetype)turquoiseColor {
    return UIColorFromRGB(0x40E0D0);
}

+ (instancetype)mediumTurquoiseColor {
    return UIColorFromRGB(0x48D1CC);
}
</code></pre>

<p>However, I have been unable to work out how to achieve the same functionality using Swift 3.0, or whether the use of Selector is even the best technique.</p>

<pre><code>func UIColorFromRGB(_ rgbValue: UInt) -&gt; UIColor {
    return UIColor(
        red: CGFloat((rgbValue &amp; 0xFF0000) &gt;&gt; 16) / 255.0,
        green: CGFloat((rgbValue &amp; 0x00FF00) &gt;&gt; 8) / 255.0,
        blue: CGFloat(rgbValue &amp; 0x0000FF) / 255.0,
        alpha: CGFloat(1.0)
    )
}

extension UIColor {
    public class var turquoise: UIColor { return UIColorFromRGB(0x40E0D0) }
}

extension UIColor {
    public class var mediumTurquoise: UIColor { return UIColorFromRGB(0x48D1CC) }
}

let myColor: UIColor = .turquoise

let name: String = "turquoise"
let colorName = "UIColor.\(name)"
let selector: Selector = NSSelectorFromString(colorName)

let colorSelected: UIColor = UIColor.perform(selector!)
</code></pre>

<blockquote>
  <p>Error: ! No 'perform' candidates produce the expected contextual result type 'UIColor'</p>
</blockquote>