Last active
December 1, 2017 16:19
-
-
Save seanonthenet/d2c0f225bbf66f6bcfcd58ade5c4eb41 to your computer and use it in GitHub Desktop.
Swift Protocol Delegate Pattern
This file contains 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 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