Skip to content

Instantly share code, notes, and snippets.

@leopic
Created July 17, 2020 23:49
Show Gist options
  • Save leopic/3459533ff8874f8ed8bda89cb933b588 to your computer and use it in GitHub Desktop.
Save leopic/3459533ff8874f8ed8bda89cb933b588 to your computer and use it in GitHub Desktop.
protocol MyProtocol {
func requiredMethod() -> Void
func optionalMethod() -> Void
}
extension MyProtocol {
func optionalMethod() -> Void {} // Default implementation
}
struct AStructThatConformsToMyProtocol:MyProtocol {
func requiredMethod() -> Void {
// this is mandatory
}
}
let myInstance = AStructThatConformsToMyProtocol()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment