如何异步调用Objective-c静态方法?

ary*_*axt 6 static-methods asynchronous objective-c

如何异步调用静态方法?

+ (void) readDataFromServerAndStoreToDatabase
{
     //do stuff here
     //might take up to 10 seconds
}
Run Code Online (Sandbox Code Playgroud)

mip*_*adi 16

使用NSThread:

[NSThread detachNewThreadSelector:@selector(readDataFromServerAndStoreToDatabase)
                         toTarget:[MyClass class]
                       withObject:nil];
Run Code Online (Sandbox Code Playgroud)


cod*_*ark 6

有几种方法可以在Objective-C中实现并发,具体取决于您运行的环境.pthreads,NSThreads,NSOperations,GCD和blocks都有自己的位置.您应该阅读Apple的"并发编程指南",无论您选择哪个平台.