在单独的线程上运行代码的最佳方式是什么?
NSInvocationOperation *operationToComplete = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(operationMethod) object:nil];
NSOperationQueue *queueToStart=[[NSOperationQueue alloc] init];
[queueToStart addOperation:operationToComplete];
-(void) operationMethod
{
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&_response error:&_error];
}
或者:
NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request
delegate:self];
我一直在做第二种方式,但对此有点困惑或使用另一种方式来做到这一点。