Protocols

The following protocols are available globally.

  • A protocol should only be adopted by Crystal class.

    // Determine the concrete theme type.
    extension Crystal: CrystalDetermined {
        public typealias Theme: AppTheme
    }
    

    Although this protocol is designed for Crystal class, Crystal class does not conform to CrystalDetermined protocol by default. When using this library, it’s your responsibility to make Crystal class conform to CrystalDetermined protocol, in order to determine the concrete theme type.

    See more

    Declaration

    Swift

    public protocol CrystalDetermined : Crystal
  • A type that has crystal extensions. You can use cst property to get extension methods.

    // Make `UIView` conform to `CrystalCompatible`.
    extension UIView: CrystalCompatible {
        public typealias Theme: AppTheme
    }
    

    When conforming to CrystalCompatible, you have to determine the concrete theme type in the conformance.

    See more

    Declaration

    Swift

    public protocol CrystalCompatible : AnyObject
  • Represent a theme type.

    // A concrete theme type.
    struct AppTheme: CrystalThemeType {
        var textColor: UIColor?
    
        static var light: AppTheme {
            return AppTheme(textColor: .blue)
        }
    
        public static var entry: CrystalThemeType {
            return Self.light
        }
    }
    

    Conform to this protocol to make your concrete theme type. You should only create one concrete theme type to satisfy Crystal, otherwise some inconsistent errors may occur.

    See more

    Declaration

    Swift

    public protocol CrystalThemeType