1

Its in login process

if(![[_emailText text] isEqualToString:@""] &&![[_passwordText text] isEqualToString:@""]){
        [self performSelectorInBackground:@selector(loginInbackground) withObject:nil];
        // Hide Keyboards
        [_emailText resignFirstResponder];
        [_passwordText resignFirstResponder];

        // Show the logging in screen
        [_loggingInView setHidden:false];
    }

They have used performSelectorInBackground,and after this

-(void)loginInbackground{
    // Add the username and password to the keychain
    keychain = [[KeychainItemWrapper alloc] initWithIdentifier:@"login" accessGroup:nil];
    [keychain setObject:@"loginData" forKey:(__bridge id)kSecAttrService];
    [keychain setObject:[[_emailText text] lowercaseString] forKey:(__bridge id)kSecAttrAccount];
    [keychain setObject:[_passwordText text] forKey:(__bridge id)kSecValueData];
    keychain = nil;

    if([self loginwithuser:[_emailText text] andPassword:[_passwordText text]]){
        [self performSelectorOnMainThread:@selector(loginCompletewithbool:) withObject:[NSNumber numberWithInt:1] waitUntilDone:TRUE] ;
    }else{
        [self performSelectorOnMainThread:@selector(loginCompletewithbool:) withObject:[NSNumber numberWithInt:0] waitUntilDone:TRUE] ;
    }

What does performSelectorOnMainThread do?

Vivek Doshi
  • 56,649
  • 12
  • 110
  • 122
  • i dont see how this is a duplicate question as the one linked, similar but different. but to answer your question briefly, run in background runs the function concurrently to the main UI thread, while run on main thread runs the function on the UI main thread, the main difference is you dont want to touch anything UI related on anything other than the main thread (because bad things can happen), so if you run a function on a background thread, then want to change the UI, you will need to run a function on the main thread again to edit the UI – Fonix Feb 02 '15 at 07:19
  • What will happen when I called "performSelectorOnMainThread" does it stop the execution of "performSelectorInBackground"? – Vivek Doshi Feb 02 '15 at 07:24
  • Nope, the function will continue as normal. `performSelectorOnMainThread:` is not blocking as far as i know – Fonix Feb 02 '15 at 07:27
  • it queues up the function to be run at the end of the current run loop i think – Fonix Feb 02 '15 at 07:31
  • @Midhun MP,I don't want to know "Whats the difference between performSelectorOnMainThread and dispatch_async on main queue?" but the flow of execution of these functions. – Vivek Doshi Feb 02 '15 at 08:28
  • Read that first answer, you'll get the answer there – Midhun MP Feb 02 '15 at 08:46
  • @Fonix: The linked question answers to the current question also. It describes how performSelectorOnMainThread works. – Midhun MP Feb 02 '15 at 08:50
  • @MidhunMP but no mention of `performSelectorInBackground` in that question/answer which this OP is specifically asking about – Fonix Feb 02 '15 at 09:01
  • @Fonix: performSelectorInBackground is similar to the mentioned method only change is that executes in the other thread (not on main thread) – Midhun MP Feb 02 '15 at 09:08
  • @Midhun MP,Sorry bro I have read that already but didn't get the answer, So I have posted my own question. – Vivek Doshi Feb 02 '15 at 11:35

0 Answers0