为什么dispatch_get_specific无法识别我创建的队列?

时间:2018-04-28 04:32:13

标签: ios

我创建了一个串行队列并使用dispatch_queue_set_specific将ID设置为队列,但是在其他类中调用此队列,我不能使用dispatch_get_specific测试来输入if语句。

这是我的创建代码:

+ (dispatch_queue_t)sharedFollowerQueue
{
    return [[self shareInstance] contextQueue];
}

- (dispatch_queue_t)contextQueue
{
    static dispatch_queue_t sharedFollowerQueue;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        sharedFollowerQueue = dispatch_queue_create("com.weuseSoftware.Instracker.UserManageTool.followerQueue", DISPATCH_QUEUE_SERIAL);
        dispatch_queue_set_specific(sharedFollowerQueue, sharedFollowerQueueKey, (__bridge void *)self, NULL);
    });
    return sharedFollowerQueue;
}

这是我的调用代码,但我无法输入if语句

- (void)queryForADayFollowersCountWithCallBack:(void (^)(NSArray <GraphEntity *> *))callBack
{
    dispatch_queue_t queue = [[self class] sharedFollowerQueue];
    NSMutableArray *graphArray = [NSMutableArray array];

    dispatch_async(queue, ^{
        if (dispatch_get_specific(sharedFollowerQueueKey)) {
            NSLog(@"----get in----");
            RLMArray *currentDayUsers = [self currentDayUsers];
            if (currentDayUsers.count == 0) {
                return;
            }
            for (int i = 0; i < currentDayUsers.count; i++) {
                MainUser *user = currentDayUsers[i];
                GraphEntity *gEntity = [[GraphEntity alloc] init];
                gEntity.userDate = user.createDate;
                gEntity.number = user.user.followed_by_count.integerValue;
                [graphArray addObject:gEntity];
            }
            dispatch_async(dispatch_get_main_queue(), ^{
                if (callBack) {
                    callBack([graphArray copy]);
                }
            });
        }
    });
}

我创建了我的密钥

static const void* const sharedFollowerQueueKey = &sharedFollowerQueueKey;

当我在创建代码中记录密钥时,我得到了密钥地址

(lldb) po sharedFollowerQueueKey
0x00000001032c41d0

然后在我的通话代码中,我得到了关键地址

    (lldb) po sharedFollowerQueueKey
0x00000001032c33e8

为什么他们不同?

0 个答案:

没有答案