iOS - [Class classMethod] results in unrecognized selector sent

孤者浪人 提交于 2019-12-13 07:18:49

问题


Due to code privacy, I have to omit part of info. Just excuse me.

In TokenRequestManager.m, there is an instance method serialQueue4TokenType:

- (dispatch_queue_t)serialQueue4TokenType:(TokenType)tokenType
{
    static NSMutableDictionary *serialQueueDict = nil;
    if (serialQueueDict == nil) {
        static dispatch_once_t onceToken;
        dispatch_once(&onceToken, ^{
            serialQueueDict = [[NSMutableDictionary alloc] initWithCapacity:TokenTypeCount];
        });
    }

    dispatch_queue_t queue;

    @synchronized (self) {
        NSString *key = [TokenManager tokenName4Type:tokenType];
        key = [key stringByAppendingString:NSStringFromClass([self class])];
        NSValue *value = serialQueueDict[key];

        if (value == nil) {
            queue = dispatch_queue_create(key.UTF8String, DISPATCH_QUEUE_SERIAL);
            value = [NSValue valueWithBytes:&queue objCType:@encode(dispatch_queue_t)];
            serialQueueDict[key] = value;
        } else {
            [value getValue:&queue];
        }
    }

    return queue;
}

Just below the @synchronized (self) { line, it calls the Class method:

+ (NSString *)tokenName4Type:(TokenType)tokenType
{
    NSString *string = nil;

    switch (tokenType) {
        case TokenTypeBiz:
            return @"TokenTypeBiz";
            break;

        case TokenTypeWeb:
        default:
            string = @"TokenTypeWeb";
            break;
    }

    return string;
}

The code just stands there, but sometimes (a few times) the app will crash at this line with unrecognized selector sent, no matter debug or release.

Any tips will be much appreciated. Thanks.

来源:https://stackoverflow.com/questions/35197217/ios-class-classmethod-results-in-unrecognized-selector-sent

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!