简体   繁体   中英

Is this correct for a NSTimer to get run on the main thread?

Hello I wanted to run a NSTimer on the main thread im not sure if they are run on the main thread by default or I have to do a special implementation ? thanks to anyone who could help

@interface RootViewController : UIViewController {

        NSTimer *minutePassed;
    }

    - (void)adViewDidLoad
    {

    minutePassed = [NSTimer scheduledTimerWithTimeInterval:60.0 target:self selector:@selector(callMinutedPassed) userInfo:nil repeats:NO];

    }

    -(void)callMinutePassed
    {
    NSLog("Minute Passed");
    }

Documentation for scheduledTimer(timeInterval:target:selector:userInfo:repeats) states Creates a timer and schedules it on the current run loop in the default mode. . That means in your instance, that it is running on the main thread. I'm assuming when you say -(void)adViewDidLoad you mean -(void)viewDidLoad() .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM