Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you don't need to inform multiple objects upon completion of the task, you could add a completion handler (objc block) to the <code>-fetchActiveUser:withPassword:</code> method (so it would become something like <code>-fetchActiveUser:withPassword:completionHandler:</code> and add the code to be executed in the completion handler. </p> <p>An example, lets say your <code>-fetchActiveUser:withPassword:completionHandler:</code> method looks like the following:</p> <pre><code>- (void)fetchActiveUser:(NSString *)user withPassword:(NSString *)pass completionHandler:(void (^)(TLUser *user, NSError *error))handler { NSURL *URL = [NSURL URLWithString:@"http://www.website.com/page.html"]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:URL]; NSOperationQueue *queue = [NSOperationQueue currentQueue]; [NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^ (NSURLResponse *response, NSData *data, NSError *error) { if (!handler) { return }; if (data) { TLUser *user = [TLUser userWithData:data]; if (user) { handler(user, nil); } else { NSError *error = // 'failed to create user' error ... handler(nil, error); } } else { handler(nil, error); } }]; } </code></pre> <p>The completion handler will be called whenever the task is finished. It will either return a TLUser object or an Error if something went wrong (bad connection, data format changed while parsing, etc...).</p> <p>You'll be able to call the method like this:</p> <pre><code>- (void)saveConfiguration:(id)sender { TLHTTPClient *RESTClient = [TLHTTPClient sharedClient]; // Performs the asynchronous fetching [RESTClient fetchActiveUser:[usernameTextField stringValue] withPassword:[passwordTextField stringValue] completionHandler:^ (TLUser *user, NSError *error) { if (user) { NSLog(@"%@", user); } else { NSLog(@"%@", error); } }]; } </code></pre> <p>Of course, in this example I've used the build in asynchronous methods of NSURLConnection in stead of AFNetworking, but you should be able to get the general idea. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload