I have this code:
protocol ColorsProtocol {
static var primary: UIColor { get }
static var primaryVariant: UIColor { get }
static var secondary: UIColor { get }
static var secondaryVariant: UIColor { get }
}
enum FakeAssetProvider {
enum FakeColorProvider: ColorsProtocol {
static var primary = UIColor.white
static var primaryVariant = UIColor.gray
static var secondary = UIColor.blue
static var secondaryVariant = UIColor.red
}
}
fileprivate var _colors: ColorsProtocol?
public struct MyLibrary {
static func setup(with colorsInstance: ColorsProtocol) {
_colors = colorsInstance
}
static var colors: ColorsProtocol {
get {
guard let colors = _colors else {
fatalError("Trying to use the colors from the MyLibrary but the it was not initialized properly!")
}
return colors
}
}
}
This compiles fine, however, when I later do something like this:
MyLibrary.setup(with: FakeAssetProvider.FakeColorProvider)
What am I missing?