But to see if I can explain delegates and blocks. I'll start with blocks first.
A block is just a function assigned to a variable. I think you have some C background, right? Well if you ever worked with function pointers, blocks and function pointers are kind of the same thing. But let's imagine a function. I won't use Objective C here, just a fake language I made up now.
void sayHello(name) {
print("hello " + name);
}
you can imagine a program that says:
sayHello("richard")
this would have the output of:
hello richard
Okay. Now blocks are most commonly used with asynchronous programming, i.e. when you're waiting on things to happen. So in our case, imagine we have to ask someone's name first. The obvious way to do that is like:
var name = askName()
sayHello(name)
However, the way iOS works is that there is only one UI thread. Imagine that we're trying to fetch the name from a website or something, having to downlaod it - that could take seconds. For those seconds, your phone will be unresponsive to taps, pinches, scrolls, etc. You can't just have your entire phone lock up while you go and try to find the name. So instead, you run askName in the background, and pass it a block (I'll use more objective-c like syntax here):
askName(onComplete:sayHello)
This pattern usually works by firing off the request, and saying when the request comes back, waking up and then running sayHello. So what we're doing here is passing code as an argument. The syntax is confusing, but something like
askName(onComplete:^void (NSString* name){
NSLog(name);
});