Skip to content

Instantly share code, notes, and snippets.

@abbeyjackson
Created November 16, 2015 17:22
Show Gist options
  • Save abbeyjackson/e247d97ae18c59e7bb0a to your computer and use it in GitHub Desktop.
Save abbeyjackson/e247d97ae18c59e7bb0a to your computer and use it in GitHub Desktop.
From ios-Developers Donny Wals.
Donny Wals [8:46 AM]
Imagine this, we’re going to build a house together. You are really good at the designing and overall building but plumbing isn’t your thing. So you want me to do the plumbing for you. You define a set of skills I need to have such as this list:
protocol NinjaPlumber {
func fixSink()
func layDownPipes()
func makeSureNothingIsClogged() -> Bool
func dance() // because we all need a dancing plumber
}
So at one point I’m going to say this:
earthAbbey.plumbingDelegate = self
or you can say this:
plumbingDelegate = Donnywals()
Point is, you have a `plumbingDelegate: NinjaPlumber?` property and I conform to the `NinjaPlumber` protocol. So I can be set as your delegate for plumbing. So we meet up, we sign our contracts and it is set up. I am now your `plumbingDelegate`. As construction moves on, I stick around an I wait until you give me tasks.
At one point you’re going to need to have the piping set up so you can start pouring concrete for the floor. Because in your house, you want the pipes embedded in concrete. So you say `plumbingDelegate?.layDownPipes()`. I’m still floating around so my `layDownPipes()` method gets called and I take care of it. When I’m done, you continue, A bit later we’re all done and you call `plumbingDelegate?. makeSureNothingIsClogged()`. When I return `true` because everything is good, you’re happy and you call `plumbingDelegate?.dance()` on me so I start dancing and we can have an amazing housewarming party. (edited)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment