O'Reilly logo

iOS 8 SDK Development, 2nd Edition by Janie Clayton, Chris Adamson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 6Waiting for Things to Happen with Closures

It’s very tempting to think of our code as a series of instructions, to be executed in order. But this falls down when any of these steps takes a long time, or worse yet, an unknown amount of time.

Imagine that instead of programming an iPhone, we’re 50 years in the future, programming a household robot to do ordinary household tasks. Let’s say we want to write a program to answer the phone (OK, and imagine there are still phones 50 years from now). We might write something like:

 
Pick up the phone.
 
Say "hello".
 
Wait for the other party to introduce themselves.
 
If they're a family member, let us know.
 
If they're a politician or an advertiser, hang up.
 
Otherwise, ask us what to do.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required