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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:39:12+00:00 2026-05-16T14:39:12+00:00

I’ve my own class which should do the request and the data processing (parsing).

  • 0

I’ve my own class which should do the request and the data processing (parsing). This class should be used from different view controllers. In this class I have implemented:

- (void)sendRequest:(NSString *)url;
- (void)requestFinished:(ASIHTTPRequest *)request;
- (void)requestFailed:(ASIHTTPRequest *)request;
- (id)parse:(NSString *)aString;

I have created a property called result. If the request arrives, requestFinished is called. In requestFinished the results are saved in result. I thought if I return a value in sendRequest I get the result back. But as I mentioned before requestFinished gets the result and so sendRequest is always returning a nil variable, because at that time the request isn’t finished.

What can I do to return a result? I want that this class can be used from different view controllers. So my first thought creating a method in my view controller and passing the result won’t work.

I read this thread Pass Result of ASIHTTPRequest "requestFinished" Back to Originating Method about using the view controller as delegate. But then I think I have to implement requestFinished and requestFailed in the view controller. The idea of not having duplicate code in different view controllers would be gone away …

Can someone 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-16T14:39:13+00:00Added an answer on May 16, 2026 at 2:39 pm

    So finally I did it with a delegate.

    In my abstraction class (*.h) I defined the following, otherwise you get

    warning: no ‘-setDarkness: ‘ method found

    warning: (Messages without a matching method signature will be assumed

    warning: to return ‘id’ and accept ‘.. .’ as arguments.)

    @protocol RssParserDelegate <NSObject>  
        - (void)displayResults:(NSDictionary *)parserResults;
    @end
    

    Than I declared an instance variable and some methods in my abstraction class (*.h):

    id _delegate;
    // ...
    - (id)delegate;  
    - (void)setDelegate:(id)new_delegate;
    

    The declaration therefore looks like (*.m):

     - (id)delegate {  
         return _delegate;  
     }  
    
     - (void)setDelegate:(id)new_delegate {  
         _delegate = new_delegate;  
     }
    

    To pass the result you have to put the following code on requestFailed and requestFinished:

    if ([_delegate respondsToSelector:@selector(displayResults:)])
        [_delegate displayResults:results];
    else  
    {   
        [NSException raise:NSInternalInconsistencyException  
                    format:@"Delegate doesn't respond to displayResults:"];  
    }
    

    I redefined sendRequest and set the incoming delegate to my instance variable:

    - (void)sendRequest:(NSString *)url withDelegate:(id)aDelegate {
        // set delegate to populate the results later
        [self setDelegate:aDelegate]; 
    

    In your view controller declare this method:

    - (void)displayResults:(NSDictionary *)results {
         // do some data processing
         ...
         // show data
         [self.tableView reloadData];
    }
    

    And I also changed the method call to sendRequest of my abstraction class:

    [yourRequest sendRequest:@"xxx" withDelegate:self]; 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a view passing on information from a database: def serve_article(request, id): served_article
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a text area in my form which accepts all possible characters from
Does anyone know how can I replace this 2 symbol below from the string
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is

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.