如果我取消NSInvocationOperation
内部操作是否正确?例子:
.h 文件:
//defined in the interface
NSInvocationOperation *op1;
NSOperationQueue *loadQueue;
.m 文件:
-(id)init{
op1 = [NSInvocationOperation new];
loadQueue = [NSOperationQueue new];
}
-(void)downloadData{
op1 = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(loadServerResponse:) object:newerRequest];
[loadQueue addOperation:op1];
}
现在我有一种从服务器下载数据的方法。我添加了一个条件来检查是否有错误。如果是这样,我将在方法内取消该操作,并在检索新登录令牌时回调相同的方法。
- (void)loadServerResponse{
if(server_error){
[op1 cancel];
//fetch login token again
[self downloadData];
return;
}
我做错什么了吗?