请看这段代码:
@interface myObject:NSObject
-(void)function:(id)param;
@end
@implementation myObject
-(void)function:(id)param
{
NSLog(@"BEFORE");
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:20]];
NSLog(@"AFTER");
}
@end
int main(int argc, char *argv[])
{
myObject *object = [[myObject alloc] init];
[NSThread detachNewThreadSelector:@selector(function:) toTarget:object withObject:nil];
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}
该function
方法被调用,但没有 20 秒的暂停。我应该怎么做才能NSRunLoop
在分离的线程中工作?