Skip to content

Instantly share code, notes, and snippets.

@Przemyslaw-Wosko
Last active October 8, 2018 17:00
Show Gist options
  • Save Przemyslaw-Wosko/cc573137664b02988ef42b91c9f69e69 to your computer and use it in GitHub Desktop.
Save Przemyslaw-Wosko/cc573137664b02988ef42b91c9f69e69 to your computer and use it in GitHub Desktop.
protocol CustomComparator {
associatedtype CustomType
static func compare(_ lhs: CustomType, _ rhs: CustomType) -> Bool
}
protocol InternalTypeProtocol {
associatedtype CustomType: CustomComparator
var property: CustomType? { get set }
}
class GenericClass<InternalType> where InternalType: InternalTypeProtocol {
let instance: InternalType? = nil
func doSomething() {
guard let property = instance?.property else { return }
print(InternalType.CustomType.compare(property, property))
// Cannot invoke 'compare' with an argument list of type '(InternalType.CustomType, InternalType.CustomType)'
}
}
class SomeClass {
let helper = GenericClass<InternalType>()
enum InternalEnum: String, CustomComparator {
typealias CustomType = InternalEnum
case myCase
static func compare(_ lhs: InternalEnum,_ rhs: InternalEnum) -> Bool {
return true
}
}
class InternalType: InternalTypeProtocol {
var property: InternalEnum?
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment