Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8626085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:56:23+00:00 2026-06-12T07:56:23+00:00

I am trying to download data from an API before displaying it to the

  • 0

I am trying to download data from an API before displaying it to the user.

Here’s what I am doing:

dispatch_queue_t concurrentQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(concurrentQueue, ^{

    __block NSMutableArray *newImages;

    dispatch_sync(concurrentQueue, ^{
        newImages = [NSMutableArray array];
        // images retrieved using `NSURLConnection sendSynchronousRequest`
    });

    dispatch_sync(dispatch_get_main_queue(), ^{
        // display images to the user
    });
});

My question is, since newImages is declared with __block, am I always guaranteed to have the latest newImages data when executing the second task at the main queue? If not, what’s the safest way to pass that array’s content into the second block and making sure its the latest content?

I think my data is getting messed up somewhere, hence why I am asking this.

If this looks fine, then I will post my full code for help with the whole thing in case something else is wrong.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T07:56:24+00:00Added an answer on June 12, 2026 at 7:56 am

    A sketch of a solution:

    q = /* custom serial queue */
    urls = /* urls array */;
    NSMutableArray *images = [NSMutableArray new];
    for (NSURL *url in URLs) {
       NSURLRequest *req = [self imageRequestForURL:url];
       dispatch_async(q, ^{
         UIImage *image = [self imageFromRequest:req];
         [images addObject:newImage];
       }
    }
    dispatch_async(q, ^{
       dispatch_async(dispatch_get_main_queue(), ^{
         [self applyUpdatesForURLs:urls withImages:images];
       });
    }
    

    The queue is a standard work queue.

    The applyUpdatesForURLs:withImages: block is guaranteed to run after all images have been downloaded, by virtue of being enqueued in a serial queue after the image download blocks.

    There’s no synchronization problems with images because all code working with it runs serially not concurrently.

    And the UI update ultimately occurs on the main thread.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to download my data from App Engine. As suggested here , I'm
I'm, trying to download some Google Analytics data from their API. I can download
I am trying to download an mp3 file from google TTS API, here is
Im trying to download share data from a stock exchange using python. The problem
i am trying to download data from a sharepoint list from a C# application.
I am trying to download a data file from a local network share to
I'm trying to download data from my Google App Engine app, using the official
I am trying to download some JSON from the google book API. The URL
I'm trying to download data from a webpage then parse it, the problem is
I am trying to download some data from WCF using RX. However Observable.FromAsyncPattern() doesn't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.