关于NSOperationQueue iOS的多线程

时间:2016-09-14 02:32:25

标签: ios objective-c multithreading

我遇到了一个问题代码示例,如下所示:

    #import "TestOperation.h"

@interface TestOperation()

@property (nonatomic, weak) id<someProtocol> delegate;
@property (nonatomic) NSOperationQueue *testQ;

@end

@implementation TestOperation

- (instancetype)initWithDelegate: (id<someProtocol>)delegate
{
    self = [super init];
    if (self) {
        _delegate = delegate;
        _testQ = [[NSOperationQueue alloc]init];
        _testQ.maxConcurrentOperationCount = 1;
    }
    return self;
}

- (void)multiThreadQueueMethod {

    //po self.delegate

    [self.testQ addOperationWithBlock:^{
        //po self.delegate
    }];
}

@end

multiThreadQueueMethod在另一个不是主要的线程上执行,这也不是testQ,当执行第一个po调用方法之后和testQ新队列开始之前,委托是有效的,但是当执行第二个委托时在testQ操作中,代理是零,那么问题是什么?

0 个答案:

没有答案
相关问题