I get a problem
here is the code
- (void)start{
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate distantFuture]];
}
- (void)nlog{
NSLog(@"cool");
}
- (void)main{
thread = [[NSThread alloc] initWithTarget:self selector:@selector(start) object:nil];
[thread start];
[self performSelector:@selector(nlog) onThread:thread withObject:nil waitUntilDone:NO];
}
when I call
[self performSelector:@selector(nlog) onThread:thread withObject:nil waitUntilDone:NO];
the thread will keeping running and I can do something in the thread later;
but if I don't call it, the thread will exit at once and can never use the thread do anything, why?
Firstly, I don't think you have correct idea on using thread:
Do not override the 'start' method of NSThread, you should override the 'main' method.
Secondly, if you want to create run loop in a thread, there should be a while loop, like this:
BTW, please refer to my answer for more details usage of NSRunLoop: Best way to make NSRunLoop wait for a flag to be set?