Last active
October 8, 2018 17:00
-
-
Save Przemyslaw-Wosko/cc573137664b02988ef42b91c9f69e69 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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