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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T07:12:43+00:00 2026-06-07T07:12:43+00:00

I have some Objective-c code that makes an asynchronous (I think lol) call to

  • 0

I have some Objective-c code that makes an asynchronous (I think lol) call to a server, but I am not too sure, what is the correct way to handle the response that comes back from the server?

I do something like this:

NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];

    // ***************
    // TODO: ok I dont really understand what this is
    NSOperationQueue *queue = [[NSOperationQueue alloc] init];
    // **************

    [NSURLConnection sendAsynchronousRequest:urlRequest queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error)
     {         
      ...

and because I am very new to Objective-C, I am not certain even where to look at how to get the values from the objects, or how to handle the NSData or the NSResponse objects.

I know my server sometimes sends back a JSON response and sometimes just a string like “ok”

Also, adding to my confusion is this tutorial:

https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/URLLoadingSystem/Tasks/UsingNSURLConnection.html

according to which I should have a few separate functions like

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response

or

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data

So my question is what is the way to get the basic returned data from the 3 variables (error, response, data) from the request, and when should I implement the methods that the tutorial I mentioned suggests? It seems like the tutorial has a much more elegant solution…but I am not sure if its overkill.

  • 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-07T07:12:45+00:00Added an answer on June 7, 2026 at 7:12 am

    Error

    NSError has a unique little feature (especially inside blocks) where when a variable and its address are passed in as an argument (in this case, a simple NSError*), the method is expected to modify the object and return a useable instance in case of error. In normal use cases where no errors occur, this should be nil, which we can log inside the completion handler part of the block:

    [NSURLConnection sendAsynchronousRequest:urlRequest queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error)
    {
    (     iferror)
             NSLog(@"Connection Error - %@", [error localizedDescription]);
    }];  
    

    Response

    NSURLResponse is not important in your case. As Apple puts it:

    Note: NSURLResponse objects do not contain the actual bytes
    representing the content of a URL. See NSURLConnection for more
    information about receiving the content data for a URL load.

    You would use an NSURLResponse for file downloads, and that’s about it. JSON is returned by an NSURLConnection object.


    Data

    Possibly the most important part of the whole deal. Your JSON response would be contained within this data, which means it has to be converted into a string, and then sent off to an interpreter so that we can pull actual ObjC objects out of the JSON values. Several widely used classes were built for just that including JSON Framework, JSONKit, and TouchJSON.


    An NSOperationQueue, by the way, is much like a thread pool, but it takes the management role. NSOperationQueue objects are sent NSOperation objects, which are then added to its internal queue and executed on threads that are also managed by the NSOperationQueue object. They are now basically useless considering the advent of GCD in iOS 4.x, but in the case of legacy software support, they are useful for executing asynchronous (or synchronous, depending on whether the isConcurrent property is set on a submitted operation) tasks on background threads.

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

Sidebar

Related Questions

I have some Objective-C code that looks like this: #define myVar 10 float f
I have some objective-c code that uses an NSLock to implement a sort of
I have an Objective C project with some C++ code, and sure enough the
I have inherited some code that will eventually be part of an API call.
I have some jquery code that is doing an ajax lookup and returning comma
I am writing a simple console application in Objective-C but I have heard that
I'm working on some cross-platform code using OpenGL and SDL, but have immediately run
I have some Objective-C code to transition between two views. I have the transition
I have been developing with objective C and the Cocoa framework for quite some
I'm very new to Objective-C, and am having some beginner issues. I have an

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.