p-x9/SwiftUIColor

New Writing Style

Closed this issue · 0 comments

p-x9 commented

Consider the following writing style

let color: Color = .iOS(.label)

To achieve this kind of writing, it is necessary to change the structure from defining static properties in the enum.

Following is a proposed new way to define it

extension Color: String {
    enum iOSConstant {
        case label = "iOS/label"
        case systemBackground = "iOS/systemBackground"

        var color: Color { Color(rawValue, bundle: .myModule) }
    }


    static func iOS(_ constant: iOSConstant) -> Color { constant.color }
}