EXECUTING PERFORMSELECTORONMAINTHREAD ON MULTITHREADED APP IN IOS?

Mikki Halpin

Total Post:23

Points:161
Posted by  Mikki Halpin
 514  View(s)
Ratings:
Rate this:

When I was creating a multithreaded app in iOS, I noticed that the following code will call the main thread:

[self performSelectorOnMainThread:@selector(rollBar:)
                       withObject:nil
                    waitUntilDone:false];

but, I am unable to create multithreaded app, so please anyone tell me the correct procedure to create multithreaded application and what code we use in other controllers to get functionality of multithread in our app.

Thanks.

  1. Tarun Kumar

    Post:214

    Points:1642
    Re: Executing performSelectorOnMainThread on multithreaded app in iOS?

    AppDelegate's init method:

    NSLog(@"First Thread:  %@", [NSThread isMultiThreaded] ? @"Yes" : @"No");
    [self performSelectorOnMainThread:@selector(setDelegate:) withObject:self waitUntilDone: NO];
    NSLog(@"Second Thread: %@", [NSThread isMultiThreaded] ? @"Yes" : @"No");

    when you run this code, the output in the console will look like this:

    2015-12-11 11:46:28.296 MyApplication[82963:20b] First Thread: No
    2015-12-11 11:46:28.297 MyApplication[82963:20b] Second Thread: No

    The second thread is also written in NSLog statement into method applicationWillTerminate:, and this told me it was not multithreaded.

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!