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

  • Home
  • SEARCH
  • 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 7032127
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:53:38+00:00 2026-05-28T00:53:38+00:00

There are problems with using synchronous requests. The problem is that I am not

  • 0

There are problems with using synchronous requests. The problem is that I am not really sure how to refactor the code below to use an asynchronous request to accomplish the following two tasks:

  1. Use a UIActivityIndicatorView subview to notify of active fetching;
  2. Implement a Reachability check before the connection request to ensure that there is an Internet connection and that the host is available, i.e. reachabilityWithHostName:@"wwww.mywebhostingisterrible.com".

Currently I have a Fetcher class with a +(Fetcher *)sharedFetcher singleton that is used in all of my view controllers to fetch data. Currently all data is fetched using the following code:

- (NSString *)stringWithUrl:(NSURL *)url {

    NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:30];

    NSData *urlData;
    NSURLResponse *response;
    NSError *error;

    urlData = [NSURLConnection sendSynchronousRequest:urlRequest
                                    returningResponse:&response
                                                error:&error];

    return [[NSString alloc] initWithData:urlData encoding:NSUTF8StringEncoding];

}

A method that fetches looks like this:

-(NSArray *)fetchDogFoodListing {
    NSString *urlString = [NSString stringWithFormat:@"%@query/dogFood/%@/%lli/%@/%@",self.connectionUrl,self.queryCriteria.dogFoodName,self.queryCriteria.dogFoodBrandId,self.queryCriteria.dogFoodIngredients,self.queryCriteria.dogFoodBrand];
    NSString *json = [self stringWithUrl:[NSURL URLWithString:urlString]];
    return [self.factory buildIKDogFoodArrayWithJSON:json];
}

and a call from the UIViewController in -(void)viewDidLoad looks like this:

self.dogFoods = [[IKFetcher sharedFetcher] fetchDogFoodListing];

I have thought about implementing a delegate in this situation but I am very shaky on how delegation ought to work. I’m not even sure which way it should go. Should the Fetcher have a FetcherDelegate that can notify the view controller of when it is done, so the UI can update? Should the view controller have a delegate so that the fetcher can update the view when stuff is done?

I’m sure based on my questions you can see my inexperience with delegation, so I would appreciate any help.

  • 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-05-28T00:53:39+00:00Added an answer on May 28, 2026 at 12:53 am

    You could do something like this

    dispatch_async(queue, ^{
        NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:30];
    
        NSData *urlData;
        NSURLResponse *response;
        NSError *error;
    
        urlData = [NSURLConnection sendSynchronousRequest:urlRequest
                                    returningResponse:&response
                                                error:&error];
        dispatch_async(dispatch_get_main_queue(), ^{
             //.. do stuff with data here...
        }
    }
    

    or you could just do the sendSynchronousRequest code inside a dispatch_sync if you want the connection to be synchronous, though you should really should be as asynchronous as possible.

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

Sidebar

Related Questions

Is there significant problem, if I write the code for embedded linux system using
Hopefully the answer is no, but are there any problems with using Request.Params instead
Due to the lack of clientaccesspolicy.xml, there appears to be problems with using Amazon
Seems there's nothing to do… using the combo prototype/lowpro, no problems at all with
I am having some problems parsing this piece of XML using SimpleXML. There is
Is there a problem with using IEnumerable<T> as a return type? FxCop complains about
Is there a problem to using javascript for styling content? My website requires javascript.
I'm having a problem using UpdateModel(theModelToUpdate) causing concurrency issues. Basically whats happening is, there
I am using AJAX modal popup in my project, but there is problem with
I'm using Blowfish.NET newest version,but there is one problem. responce = new byte[6] {

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.