Add hex init to Color, cleanup assertionFailure (#69)

* Add hex init to Color, cleanup assertionFailure
* Add doc comment
This commit is contained in:
Max Desiatov 2019-03-19 12:40:03 +00:00 committed by GitHub
parent 7d6107740a
commit 156b775c4e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View File

@ -35,3 +35,14 @@ public struct Color: Equatable {
public static var green = Color(red: 0.0, green: 1.0, blue: 0.0, alpha: 1.0)
public static var blue = Color(red: 0.0, green: 0.0, blue: 1.0, alpha: 1.0)
}
extension Color: ExpressibleByIntegerLiteral {
/// Allows initializing value of `Color` type from hex values
public init(integerLiteral bitMask: UInt32) {
red = Double((bitMask & 0xFF0000) >> 16) / 255
green = Double((bitMask & 0x00FF00) >> 8) / 255
blue = Double(bitMask & 0x0000FF) / 255
alpha = 1
space = .sRGB
}
}

View File

@ -112,7 +112,7 @@ public final class Hooks {
defer { refIndex += 1 }
guard let component = component else {
assertionFailure("hooks.state should only be called within `render`")
assertionFailure("hooks.ref should only be called within `render`")
return initial
}