Skip to content

Instantly share code, notes, and snippets.

@abbottmg
Last active March 6, 2019 17:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abbottmg/1d6df49826cbf6233148 to your computer and use it in GitHub Desktop.
Save abbottmg/1d6df49826cbf6233148 to your computer and use it in GitHub Desktop.
protocol Named {
func GetName() -> String
}
protocol CasedNamed { // previously "NamedExtension"
func GetLowercaseName() -> String
func GetUppercaseName() -> String
}
extension CasedName where Self: Named {
func GetLowercaseName() -> String {
return self.GetName().lowercaseString
}
func GetUppercaseName() -> String {
return self.GetName().uppercaseString
}
}
extension Int : Named, CasedNamed {
func GetName() -> String {
return "Int"
}
}
1.GetName() // "Int"
1.GetLowercaseName() // "int"
1.GetUppercaseName() // "INT"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment