Skip to content

Instantly share code, notes, and snippets.

@seanonthenet
Last active December 1, 2017 16:19
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 seanonthenet/d2c0f225bbf66f6bcfcd58ade5c4eb41 to your computer and use it in GitHub Desktop.
Save seanonthenet/d2c0f225bbf66f6bcfcd58ade5c4eb41 to your computer and use it in GitHub Desktop.
Swift Protocol Delegate Pattern
// protocol declaration
protocol myDelegate {
func myFunction()
}
// Receiver / Performer / Intern
class Receiver: SomeClass, myDelegate {
// instantiate instance of sender class before this
caller.delegateInstance = self
func myFunction(){
print("Does something")
}
}
// Caller / Sender / Boss
class Caller: OtherClass {
var delegateInstance: myDelegate!
delegateInstance.myFunction()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment