Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You could do this using GCD with less code and using fewer resources. This is how you could do it:</p> <p>In <code>viewDidLoad</code> call a block asynchronously (using <code>dispatch_async</code>) that does the following:</p> <ol> <li>Load the data with a synchronous call and handle timeouts if it failed.</li> <li>If successful, inform the main thread to update the UI.</li> <li>Queue a new block to run after a delay that does the same thing (using <code>dispatch_after</code>).</li> </ol> <p>To call back to the main thread from another thread I can think of these methods:</p> <ol> <li>If you want to update a custom view, you can set <code>setNeedsDisplay</code> from your block</li> <li>Otherwise, you could queue a block on what's called "main queue", which is a queue running on the main thread. You get this queue by calling <code>dispatch_get_main_queue</code>. and then treat it like any other queue (for example you can add your block by calling <code>dispatch_async</code>).</li> <li>If you don't want to use blocks you can use the <code>NSObject</code>'s <code>performSelectorOnMainThread:withObject:waitUntilDone:</code> method.</li> </ol> <p>See <a href="http://developer.apple.com/mac/library/documentation/Performance/Reference/GCD_libdispatch_Ref/Reference/reference.html" rel="nofollow noreferrer">GCD Reference</a> for more details.</p> <p>That said, you should never keep performing small requests so frequently (unless for specific tasks like fetching game data or something). It will severely reduce battery life by keeping antenna from sleeping.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload