Last active
March 6, 2020 15:32
-
-
Save aronbudinszky/2d84f8a62ec09673f54ae7b4a78617b0 to your computer and use it in GitHub Desktop.
Support named assets via enum values (to avoid string literals).
This file contains 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
import Foundation | |
import SwiftUI | |
/// Extend Color to support named assets | |
extension Color { | |
enum Assets: String, RawRepresentable { | |
case appTextColor | |
/// Place all your color assets here...the enum case should equal to the name you use in your Asset library | |
} | |
init(asset: Color.Assets) { | |
self.init(asset.rawValue) | |
} | |
} | |
/// Extend UIColor to support named assets | |
extension UIColor { | |
convenience init(asset: Color.Assets) { | |
// Force unwrap okay because we are sure that Color.Assets are available | |
self.init(named: asset.rawValue)! | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment