This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension UIColor { | |
enum Error: ErrorType { | |
case Parsing(String) | |
} | |
convenience init(hex input: String) throws { | |
let hex = input.stringByTrimmingCharactersInSet(NSCharacterSet.alphanumericCharacterSet().invertedSet) | |
var int = UInt32() | |
guard NSScanner(string: hex).scanHexInt(&int) else { | |
throw Error.Parsing("Unable to scan hexadecimal integer") |