Running NSTimer Within an NSThread?

前端 未结 2 941
感动是毒
感动是毒 2021-01-24 05:05

I am trying to run a timer in the background of my application, i am using the timer heavily in my application and i\'d rather running it in the background, However i am getting

2条回答
  •  情深已故
    2021-01-24 05:47

    Off the cuff, the NSRunLoop you have in there seems a bit out of place. From the docs:

    In general, your application does not need to either create or explicitly manage NSRunLoop objects. Each NSThread object, including the application’s main thread, has an NSRunLoop object automatically created for it as needed. If you need to access the current thread’s run loop, you do so with the class method currentRunLoop.

    You have a timer, starting a thread, that gets the current run loop and tries to start running it. Do you want to associate the timer with that run loop?

    Via a call to:

    (void)addTimer:(NSTimer *)aTimer forMode:(NSString *)mode

    ?

提交回复
热议问题