Presented at Mobiconf 2015: http://2015.mobiconf.org
Ash Furrow, Artsy
Evolution of Async Programming
• All decisions are made in a context
• iOS developers are human; we tend to conﬂate things
• Older solutions have value, too
• There are beneﬁts to using older technology
in a context
What’s a context?
• What technology is available?
• How much do I understand the options? What about my team?
• How popular is the technology?
• How stable are the tools I would need to use?
• How easy is it to learn?
• How quickly do I need to complete the task?
Decisions aren’t made in a vacuum
Unique, in space…
Adopting a codebase
Context includes experience
But you don’t have to
You can never understand
the context a decision was made in
It is enough to appreciate that a
iOS developers conﬂate things
⽌ •́ ﹏ •̀ ⽎
verb [ with obj. ]
combine (two or more ideas,
texts, etc.) into one.
Humans look for patterns
What does this have to do with
Some popular development practice
When learning iOS, we’re bad at that practice
Popular development practice is bad
We get better at iOS development
New thing comes out, and we’re good at it
New thing is good
This is why new things are
always so appealing
Why do iOS devs do this?
There are several explanations
iOS is young
… really young
Always older APIs for us to blame
iOS is constantly changing
I’ve done this a lot
You probably have, too
Don’t be hard on yourself!
And don’t be hard on others!
We’re all just winging it!
/ / ＼＼
| |、 \
| ⼃丿 ＼
| | ) /
ノ ) Lů
Older solutions have merit
–Lots of people, for hundreds of years
“Those who don’t study history are
doomed to repeat it.”
–Me, just now
“Those who don’t study the past can’t make
informed decisions about the present.”
History of Async Programming
• iOS 2+
• Supports delays
• iOS 2+
• Difﬁcult, mostly
• Sometimes, kind of cancellable
• iOS 2+
• Supports concurrency
• Supports dependency graphs
• More boilerplate
Blocks / GCD
• iOS 4+
• Super-dangerous (reference cycles)
• Better in Swift
• Not cancellable
NSOperation + Blocks
• iOS 4+
• Everything from NSOperation, but also with blocks
• Less boilerplate
• Slightly more verbose than blocks (this is Objective-C, remember)
• Not popular – why?
• iOS 7+
• No one knows what it’s for
• I don’t know
• Do you know?
• iOS 7+
• Network-speciﬁc async abstraction
• Very nice
• Seriously, very nice
• (Will discuss more later)
Let’s build something
Those are only tools
• Adding block callbacks to UIGestureRecognizer, UIAlertView, etc
• Futures, promises
• Sequences, signals (FRP)
Those are great abstractions, but…
I feel we ignore NSOperation
• Chainable, dependency graphs
• Concurrency support
• Completion handlers
• Interoperate with GCD
Why so GCDerious?
• iOS devs favour GCD over other suitable abstractions
• NSOperation is unfamiliar, feels unnecessary
• Apple is good at marketing
Different solutions work for
Get familiar with your options
Don’t be mean to developers
who disagree with you
There are beneﬁts to older solutions
Developers (like me ) tend to say
Objective-C is “old and busted”
Old, yes, but not busted
• “Old” is stable
• “Old” is usually well-documented
• “Old” is easy to hire for
• “Old” has a lot of helpful resources, libraries, tutorials, etc
Let’s look at another example
• Very protocol-oriented
• Separate delegates isolate different areas of concern
• One object may conform to all protocols
• Many, small protocols are better than one massive one
• Swift protocols don’t even support optional functions!
• Could have been completely blocks-based…
• Instead, based on ideas behind NSOperation
• NSURLSession probably wraps an NSOperation, anyway
• This is good! No leaky abstractions
Try to be more like
Go read NSOperation.h
• Decisions are made in an unknowable context
• Developers are bad at evaluating things
• New and shiny things aren’t always better
• Old solutions carry extrinsic beneﬁts
So what’s the best way to do
asynchronous programming on iOS?