CLI to change all Swift UIColor initializer to HSB initializer
Swift 4.2+ Xcode 10+
Run make command.
$ make install
When you write Swift code like below:
import UIKit
let color1 = UIColor(red: 0.2, green: 0.4, blue: 1.0, alpha: 1.0)
let color2 = UIColor.init(red: 0.5, green: 0.4, blue: 0.3, alpha: 0.4)
let color3 = UIColor(displayP3Red: 0.2, green: 0.4, blue: 1.0, alpha: 1.0)
let color4 = UIColor(white: 0.4, alpha: 0.8)
Then you run this command, you can get like this:
import UIKit
let color1 = UIColor(hue: 0.625, saturation: 0.8, brightness: 1.0, alpha: 1.0)
let color2 = UIColor.init(hue: 0.08333333333333333, saturation: 0.4, brightness: 0.5, alpha: 0.4)
let color3 = UIColor(hue: 0.610491388406303, saturation: 0.8959992453455925, brightness: 1.0, alpha: 1.0)
let color4 = UIColor(hue: 0.0, saturation: 0.0, brightness: 0.4, alpha: 0.8)
Of course, the output of these code is same. (note: Color value with display P3 color space will sometimes change because of changing color space, but it is indistinguishable with the naked eye.)
This command output converted code to standard ouput.
$ absolute-hsb dump <file-path>
This command replace original code with converted code.
$ absolute-hsb rewrite <file-path>
This command show the help.
$ absolute-hsb help
MIT License.
This library based on this entry and library. And I started to develop this library in "Open Source Swift workshop in try! Swift 2019".