Day 119 – Make my first iPhone app in 16 weeks (Concurrency)

This is part of “Make my first iPhone app in 16 weeks” series.

Concurrency

When to avoid:

  1. Networking (use asynchronous API’s instead)
    1. initWithContentsofURL needs to be used with asynchronous API’s. Otherwise, it will block the main thread.
  2. Reachability (use asynchronous API’s instead)
  3. Idle Behavior (use NSTimer instead)

Best concurrency architecture

  1. Thread confinement – one object on one thread (NSOperation provides this functionality)

NSOperation

  1. Encapsulates code & data
  2. Can query for the state of execution (isExecuting, isFinished, and isCancelled)
  3. Can set dependencies (let a particular operation be dependent upon another operation) – very useful!
  4. Can set priority

NSOperationQueue

Regulates a set of NSOperation objects

  1. Can suspend and resume
  2. Can up-throttle or down-throttle the queue

Leave a Reply

Your email address will not be published. Required fields are marked *

* Copy This Password *

* Type Or Paste Password Here *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>