0

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)

I get this result: compilation error

What am I missing?

lawicko
  • 7,096
  • 2
  • 35
  • 47
  • Duplicate of https://stackoverflow.com/questions/33112559/protocol-doesnt-conform-to-itself ? – matt Jun 11 '21 at 15:40

0 Answers0