在单独的线程上运行代码的最佳方式是什么?是不是:
[NSThread detachNewThreadSelector: @selector(doStuff) toTarget:self withObject:NULL];或者:
NSOperationQueue *queue = [NSOperationQueue new];
NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:self
selector:@selector(doStuff:)
object:nil;
[queue addOperation:operation];
[operation release];
[queue release];我一直在使用第二种方法,但我一直在阅读的Wesley Cookbook使用了第一种方法。
发布于 2017-06-30 06:34:04
我已经在NSThread上添加了一个类别,它可以让你轻松地在块中执行线程。你可以从这里复制代码。
https://medium.com/@umairhassanbaig/ios-how-to-perform-a-background-thread-and-main-thread-with-ease-11f5138ba380
https://stackoverflow.com/questions/3869217
复制相似问题