vds_ios/VDS/Protocols/Colorable.swift
Matt Bruce 1e046fa336 removed / replaced anything to do with model
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
2022-10-20 15:41:41 -05:00

51 lines
1.2 KiB
Swift

//
// Colorable.swift
// VDS
//
// Created by Matt Bruce on 10/10/22.
//
import Foundation
import UIKit
public protocol Colorable<ObjectType> {
associatedtype ObjectType
func getColor(_ object: ObjectType) -> UIColor
}
extension Colorable {
fileprivate func getColor(_ object: Any) -> UIColor {
guard let model = object as? ObjectType else {
assertionFailure("Invalid ObjectType, Expecting type \(ObjectType.self), received \(object) ")
return .black
}
return getColor(model)
}
public func eraseToAnyColorable() -> AnyColorable { AnyColorable(self) }
}
public struct GenericColorable<ObjectType>: Colorable, Withable {
private var wrapped: any Colorable<ObjectType>
public init<C: Colorable>(colorable: C) where C.ObjectType == ObjectType {
wrapped = colorable
}
public func getColor(_ object: ObjectType) -> UIColor {
wrapped.getColor(object)
}
}
public struct AnyColorable: Colorable, Withable {
private let wrapped: any Colorable
public init(_ colorable: any Colorable) {
wrapped = colorable
}
public func getColor(_ object: Any) -> UIColor {
wrapped.getColor(object)
}
}