Evolution of Asynchronous Programming on iOS

0ebf471a3ae8df42a84f93a7efbbdbd0?s=47 Ash Furrow
October 02, 2015

Evolution of Asynchronous Programming on iOS

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

0ebf471a3ae8df42a84f93a7efbbdbd0?s=128

Ash Furrow

October 02, 2015
Tweet

Transcript

  1. 3.

    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. 4.

    (•_•) <) )╯ / \ \(•_•) ( (> / \

    (•_•) <) )> / \ Decisions are made in a context
  3. 6.

    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. 11.
  5. 15.
  6. 17.
  7. 18.
  8. 20.

    Some popular development practice When learning iOS, we’re bad at

    that practice Popular development practice is bad + =
  9. 21.

    We get better at iOS development New thing comes out,

    and we’re good at it New thing is good + =
  10. 30.

    ⊂_ヽ   \\ Λ_Λ    \( ˇωˇ)    / ⌒   / へ\

      /  / \\ ƀɹϊɹɹ ヽ_つ   / /  ( (ヽ  | |、 \  | ⼃丿 \  | |  ) / ノ )  Lů Older solutions have merit
  11. 31.

    –Lots of people, for hundreds of years “Those who don’t

    study history are doomed to repeat it.”
  12. 32.
  13. 33.

    –Me, just now “Those who don’t study the past can’t

    make informed decisions about the present.”
  14. 35.
  15. 37.
  16. 38.

    Blocks / GCD • iOS 4+ • Super-easy • Super-dangerous

    (reference cycles) • Better in Swift • Not cancellable
  17. 39.

    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?
  18. 40.

    NSProgress • iOS 7+ • Confusing • No one knows

    what it’s for • I don’t know • Do you know?
  19. 41.

    NSURLSessionTask • iOS 7+ • Network-specific async abstraction • Very

    nice • Seriously, very nice • (Will discuss more later)
  20. 46.

    NSOperation • Cancellable • Chainable, dependency graphs • Concurrency support

    • Completion handlers • Prioritization • Interoperate with GCD
  21. 48.

    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
  22. 49.
  23. 56.

    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
  24. 60.

    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!
  25. 61.

    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
  26. 64.

    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