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 Collection { | |
/// Returns the element at the specified index if it is within bounds, otherwise nil. | |
subscript(safe index: Index) -> Element? { | |
indices.contains(index) ? self[index] : nil | |
} | |
} |
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 { | |
static func adapt(lightModeColor: UIColor?, darkModeColor: UIColor?) -> UIColor { | |
guard let lightModeColor = lightModeColor, | |
let darkModeColor = darkModeColor else { | |
fatalError("No color") | |
} | |
if #available(iOS 13, *) { | |
return UIColor { (traitCollection: UITraitCollection) -> UIColor in | |
if traitCollection.userInterfaceStyle == .dark { | |
/// Return the color for Dark Mode |
NewerOlder