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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:12:09+00:00 2026-06-12T00:12:09+00:00

For the iOS app I’m working on, I’m currently writing a singleton class that

  • 0

For the iOS app I’m working on, I’m currently writing a singleton class that handles asynchronous requests to a server. Here’s an example of one of the methods –

- (void)registerUser:(CBCUserRegistration *)userRegistration delegate:(id)<CBCUserRegistrationDelegate>delegate;

within this method, an NSURLConnection is created and sends an asynchronous request. At this point, i need a way to tie the delegate object to the NSURLConnection, so thats when

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

is called, I know which delegate to inform. Because the requests are asynchronous, there may be more than one request going at any time. My initial though was to use an NSMutableDictionary, setting the NSURLConnection as the key and the delegate as the value, but the keys are copied so thats a no go. Can anyone suggest another way to track this?

Thanks in advance.

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

    Avoid using an NSDictionary for this. Instead take an object-oriented approach:

    Write a class MyConnection that implements the required NSURLConnectionDelegate callbacks and has a property/ivar of the id<CBCUserRegistrationDelegate>type. Add a start method to MyConnection that creates an NSURLConnection, assigns itself a delegate of that connection, and starts it. Now you can create an instance of MyConnection for every URL request you do. MyConnection keeps hold of the CBCUserRegistrationDelegate and forwards the result it receives from the NSURLConnection.

    However, using delegate here is a bit old-fashioned. Use blocks instead, especially if your project uses ARC. NSURLConnection provides a convenient method to do async requests: [NSURLConnection sendAsynchronousRequest:queue:completionHandler:].

    For example:

    - (void)registerUser:(CBCUserRegistration *)userRegistration delegate:(id<CBCUserRegistrationDelegate>)delegate
    {
        NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://mysite.com/register"]];
        [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue]
                               completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
            [delegate processRegistrationResponseData:data];
        }];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing an iOS app that streams video and audio over the network. I
I am writing an iOS app that uses live audio analysis. It has an
The iOS app I'm working on handles very large files (largest being 2.7 gig
Im currently writing an ios app which uses google map api's to measure driving
In the iOS app I'm writing, we have an add photo button that's pretty
I have an iOS app sending requests to a PHP based web service ,
I have an iOS app that uses a number of enums for valid values,
I have an iOS app with a UITableView that has flexible width, which allow
I write a simple ios app. All of my views are created programmatically. Here
For an iOS app I am working on with RestKit I need to parse

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.