Skip to content

Instantly share code, notes, and snippets.

@ezura
Created June 1, 2017 15:07
Show Gist options
  • Select an option

  • Save ezura/dbb249c5663e97985f49483e6bbac2e5 to your computer and use it in GitHub Desktop.

Select an option

Save ezura/dbb249c5663e97985f49483e6bbac2e5 to your computer and use it in GitHub Desktop.
protocol Permission {}
enum Default: Permission {}
enum Strict: Permission {}
protocol P {
associatedtype PermissionMode: Permission = Default
func f() -> String
}
extension P {
func callF() -> String {
return "default " + #function + " - " + f()
}
func f() -> String {
return "default " + #function + " - " + v
}
var v: String { return "default " + #function }
}
extension P where Self.PermissionMode == Strict {
func f() -> String {
return "Self.PermissionMode == Strict " + #function + " - " + v
}
}
struct A: P {}
struct B: P {
typealias PermissionMode = Strict
}
A().callF() // "default callF() - default f() - default v"
B().callF() // "default callF() - Self.PermissionMode == Strict f() - default v"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment