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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:36:10+00:00 2026-06-10T14:36:10+00:00

This may be a naive question, but I’ll ask it anyway as I cannot

  • 0

This may be a naive question, but I’ll ask it anyway as I cannot find any documentation that clears up this issue in my head.

I’m running iOS5.1 both on device and in the simulator with Xcode45-DP4.

I have a loop that iterates over an array of a number of instances of a class. In that loop I use performSelector on the instances to start a thread that does some relatively slow network operations — pulling down data that I’d rather do in the background.

    [arrayOfFriends enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
        Friend *f = (Friend*)obj;
        iOSSLog(@"%d", idx);
        [f performSelectorInBackground:@selector(showDescription) withObject:nil];



-(void)fetchTwitterStatus
{
iOSSLog(@"Trying to fetch twitterstatus %@ %@", self.hash, self.twitterUserName);
[mLocalTwitterUser fetchTwitterAPIUserStatusWithScreenName:twitterUserName
                                     withCompletionHandler:^(NSArray *arrayOfStatus, NSError *error) {
                                         if(error) {
                                             iOSSLog(@"%@", error);
                                         } else {
                                             iOSSLog(@"Got twitterstatus %@ %d", self.twitterUserName, [arrayOfStatus count]);
                                             @synchronized(items) {
                                                 [items addObjectsFromArray:arrayOfStatus];
                                             }
                                         }
                                     }];
}

In my test case there are four instances. Each instance gets its selector, you know..selected. The first three definitely start but only the last actually completes as indicated by the log line that says “Got twitterstatus…” Which is weird.

I can also verify that the method the selector calls “fetchTwitterStatus”

What is the little fundamental nugget of multithreading that I’m missing here?

EDIT: here’s fetchTwitterAPIUserStatusWithScreenName…quite a bit here, but effectively it’s calling the Twitter API Endpoint user_timeline with a JSON response.

- (void)fetchTwitterUserStatusWithScreenName:(NSString *)screenname
                          excludeReplies:(BOOL)excludeReplies
                   withCompletionHandler:(OtterTwitterSearchHandler)completionHandler

{
self.twitterAPIStatusHandler = completionHandler;
//self.fetchTwitterUserStatusHandler = completionHandler;
NSString *urlString = [NSString stringWithFormat:@"https://api.twitter.com/1/statuses/user_timeline.json?screen_name=%@&include_rts=true&include_entities=true&exclude_replies=%@&count=50", screenname, excludeReplies?@"true":@"false"];
NSURL *url = [NSURL URLWithString:urlString];

#warning this isn't the way to do it - just checking the cache for refresh of the scroller
[[ASIDownloadCache sharedCache]removeCachedDataForURL:url];

iOSSRequest *request = [[iOSSRequest alloc] initWithURL:url
                                             parameters:nil
                                          requestMethod:iOSSRequestMethodGET];

NSMutableDictionary *oauthParams = [NSMutableDictionary dictionary];
[oauthParams setObject:[[Twitter sharedService] apiKey] forKey:kASIOAuthConsumerKey];
[oauthParams setObject:[[Twitter sharedService] apiSecret] forKey:kASIOAuthConsumerSecret];
[oauthParams setObject:[self oAuthAccessToken] forKey:kASIOAuthTokenKey];
[oauthParams setObject:kASIOAuthSignatureMethodHMAC_SHA1 forKey:kASIOAuthSignatureMethodKey];
[oauthParams setObject:@"1.0" forKey:kASIOAuthVersionKey];
[oauthParams setObject:[self oAuthAccessTokenSecret] forKey:kASIOAuthTokenSecretKey];

request.oauth_params = oauthParams;


[request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
    if (error) {
        if (self.twitterAPIStatusHandler) {
            self.twitterAPIStatusHandler(nil, error);
            self.twitterAPIStatusHandler = nil;
        }
    } else {
        NSMutableArray *recentStatusForTwitterUser = [[NSMutableArray alloc]init];
        NSArray *array = [Twitter JSONFromData:responseData];
        [array enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
            TwitterStatus *twitterStatus = nil;
            twitterStatus = [[TwitterStatus alloc]initWithDictionary:obj];
            [recentStatusForTwitterUser addObject:twitterStatus];
        }];
        if (self.twitterAPIStatusHandler) {
            self.twitterAPIStatusHandler(recentStatusForTwitterUser, nil);
            self.twitterAPIStatusHandler = nil;
        }
    }
}];

}
  • 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-10T14:36:12+00:00Added an answer on June 10, 2026 at 2:36 pm

    I’d suggest using the asynchronous abstractions already provided where possible. It would be a fairly rare/unique situation where you need to deal with threads directly.

    I’ve found treating each network-based background task as a synchronous NSOperation on a queue works really well.

    Get a new instance of NSOperationQueue, configure it, add tasks to it, and manage the queue. The benefit of this approach is that each task can be implemented as a simple synchronous task, and the queue takes care of concurrency. Optionally you can set dependencies (this task must complete before that one).

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

Sidebar

Related Questions

This may be a pretty naive and stupid question, but I'm going to ask
I think this may be a naive question. I often find that I've got
This may be a simple question but I can;t find the answer anywhere. Here
This may be a terribly naive question but I was just wondering if the
This may be a naive question, but does RSpec's testing DSL violate the law
this may be a naive question, but, as asked in the object, what is
This question may seem to be naive. But I think it'll be much worse
This question may be naive, but: is there const keyword in C? since which
Note: this question may not be suitable to SO, but I'd like to ask
This question may seem naive. I don't want to reach the power of this

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.