我正在使用以下代码进行nsoperation。问题是所有三个任务都串行运行。我该怎么做才能使任务并行运行。我尝试实现 start 和 isconcurrent 方法但它不起作用。请帮助...给定是我的 uaview 控制器类
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
Store *S=[ [Store alloc] init];
S.a=25;
NSOperationQueue *someQueue = [NSOperationQueue currentQueue];
someQueue.MaxConcurrentOperationCount = 3;
NSInvocationOperation *invocationOp2 = [[NSInvocationOperation alloc] initWithTarget:self
selector:@selector(ymain)
object:nil];
NSInvocationOperation *invocationOp3 = [[NSInvocationOperation alloc] initWithTarget:self
selector:@selector(ymain2)
object:nil];
NSInvocationOperation *invocationOp4 = [[NSInvocationOperation alloc] initWithTarget:self
selector:@selector(ymain3)
object:nil];
[someQueue addOperation:invocationOp2];
[someQueue addOperation:invocationOp3];
[someQueue addOperation:invocationOp4];
}
-(void)ymain
{
for (int i = 0 ; i < 10000 ; i++) {
NSLog(@"in the A main"); }
}
这是另一个被子类化的类
@interface A : NSOperation
@end
@implementation A
bool executing;
bool finished;
-(void)main
{
}
- (BOOL)isConcurrent
{
return YES;
}
- (BOOL)isReady
{
return YES;
}