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 8359289
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:05:57+00:00 2026-06-09T11:05:57+00:00

I recently added threading to an app so that network requests are not blocking

  • 0

I recently added threading to an app so that network requests are not blocking the UI. On doing this, I discovered that I could no longer set my instance variable the same way as I had before implementing threading. My instance variable is a property declared as follows:

@property (nonatomic, strong) NSMutableArray *currentTopPlaces;

Here is how I incorrectly set my instance variable self.currentTopPlaces:

dispatch_queue_t downloadQueue = dispatch_queue_create("Flickr Top Places Downloader", NULL);
dispatch_async(downloadQueue, ^{
    __block NSArray *topPlaces = [FlickrFetcher topPlaces];
    dispatch_async(dispatch_get_main_queue(), ^{
        self.tableRowCount = [topPlaces count];
        [[self currentTopPlaces] setArray:topPlaces];
    });

Using [self currentTopPlace] setArray:topPlaces] worked fine in the blocking version, before I started using GCD.

Now, I must set it like so for things to work correctly:

dispatch_queue_t downloadQueue = dispatch_queue_create("Flickr Top Places Downloader", NULL);
dispatch_async(downloadQueue, ^{
    __block NSArray *topPlaces = [FlickrFetcher topPlaces];
    dispatch_async(dispatch_get_main_queue(), ^{
        self.tableRowCount = [topPlaces count];
        self.currentTopPlaces = topPlaces;
    });

Can someone explain to me the difference between using:

[[self currentTopPlaces] setArray:topPlaces];

and:

self.currentTopPlaces = topPlaces;

Specifically, why the “setArray” call did not work in a threaded block?

I thought dot notation in Objective-C is syntactic sugar and not mandatory. I would like to know the “non-sugared” way to achieve the same behavior.

  • 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-09T11:05:59+00:00Added an answer on June 9, 2026 at 11:05 am

    [self currentTopPlaces] and self.currentTopPlaces are in fact identical, but

    [self.currentTopPlaces setArray:topPlaces]; // (1)
    self.currentTopPlaces = topPlaces; // (2)
    

    are not. (1) replaces all elements of self.currentTopPlaces with those from topPlaces. (2) assigns a new value to self.currentTopPlaces (releasing the old value if it was not nil).

    A difference occurs if self.currentTopPlaces is nil: (1) does nothing, because the setArray: method is sent to nil. (2) assigns a new value to self.currentTopPlaces.

    Btw: The __block modifier is not necessary in your code, because the block will not change the value of topPlaces.

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

Sidebar

Related Questions

I've recently added the wibiya toolbar to my site. Since doing that, my jquery
We recently added a feature to our software that requires .NET 2.0 SP2. This
I recently added namespaces to my rails app. I had a form that will
I recently added a stored procedure to my SQL Azure database. I added that
I recently added Android's LVL copy protection to my app, and the results have
I recently added CKEditor to my app and I would like to include my
I recently added devise confirmable module to my rails app. My application runs well
I recently added a new column to a MySQL database (featured), then added that
I recently added some namespaces to my web.config file so that all of my
I recently added a splash screen to my WPF app.My app loads fast so

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.