0

I have a class which inherits NSThread:

@interface MyService : NSThread {
...
}

In another class, I get a instance of MySerivce:

MyService *service = [self getServiceInstance];

// here, how can I get the NSRunLoop instance out from service ?

I want to get the NSRunLoop instance of service , how to get it?

Leem.fin
  • 40,781
  • 83
  • 202
  • 354

1 Answers1

1

The runloop isn't a property of the thread class and you can use +[NSRunLoop currentRunLoop] to get the runloop for the current thread.

Note that non-main threads may not have a runloop associated with them, unless you create it yourself.

Droppy
  • 9,691
  • 1
  • 20
  • 27
  • But `+[NSRunLoop currentRunLoop]` returns the run loop of calling thread, I want the NSRunLoop of MyService thread. Could you please use my code snippet to show how to get NSRunLoop of MyService thread. Thanks. – Leem.fin Jun 13 '16 at 14:00
  • @Leem.fin You could, of course, store the thread's runloop as an instance variable of the thread class when it starts. As noted in my answer, you might need to create it first though... – Droppy Jun 13 '16 at 14:11
  • 'RunLoop.current' for swift 5.2 – Mr.Fingers Jun 08 '20 at 09:07