Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Evolution of Asynchronous Programming on iOS

Ash Furrow
October 02, 2015

Evolution of Asynchronous Programming on iOS

Presented at Mobiconf 2015: http://2015.mobiconf.org

Ash Furrow

October 02, 2015
Tweet

More Decks by Ash Furrow

Other Decks in Programming

Transcript

  1. Agenda • All decisions are made in a context •

    iOS developers are human; we tend to conflate things • Older solutions have value, too • There are benefits to using older technology
  2. (•_•) <) )╯ / \ \(•_•) ( (> / \

    (•_•) <) )> / \ Decisions are made in a context
  3. Contextual Questions • 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?
  4. Some popular development practice When learning iOS, we’re bad at

    that practice Popular development practice is bad + =
  5. We get better at iOS development New thing comes out,

    and we’re good at it New thing is good + =
  6. ⊂_ヽ   \\ Λ_Λ    \( ˇωˇ)    / ⌒   / へ\

      /  / \\ ƀɹϊɹɹ ヽ_つ   / /  ( (ヽ  | |、 \  | ⼃丿 \  | |  ) / ノ )  Lů Older solutions have merit
  7. –Lots of people, for hundreds of years “Those who don’t

    study history are doomed to repeat it.”
  8. –Me, just now “Those who don’t study the past can’t

    make informed decisions about the present.”
  9. Blocks / GCD • iOS 4+ • Super-easy • Super-dangerous

    (reference cycles) • Better in Swift • Not cancellable
  10. 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?
  11. NSProgress • iOS 7+ • Confusing • No one knows

    what it’s for • I don’t know • Do you know?
  12. NSURLSessionTask • iOS 7+ • Network-specific async abstraction • Very

    nice • Seriously, very nice • (Will discuss more later)
  13. NSOperation • Cancellable • Chainable, dependency graphs • Concurrency support

    • Completion handlers • Prioritization • Interoperate with GCD
  14. Why GCD? • iOS devs favour GCD over other suitable

    abstractions • Why? • NSOperation is unfamiliar, feels unnecessary • Not-invented-here-syndrome • Apple is good at marketing
  15. Older Technology • “Old” is stable • “Old” is usually

    well-documented • “Old” is easy to hire for • “Old” has a lot of helpful resources, libraries, tutorials, etc
  16. NSURLSession • 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!
  17. NSURLSession • Could have been completely blocks-based… • Instead, based

    on ideas behind NSOperation • NSURLSession probably wraps an NSOperation, anyway • This is good! No leaky abstractions
  18. Wrap Up • 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 benefits