- (BOOL)parserJSONString:(NSString *)jsonString error:(NSError **)anError {
   //some data getting
   //error handle

    NSString *description = @"phone number couldn't be using";
    NSString *recoverySuggestion = @"Please provide an other phone number.";
    NSInteger errorCode = -1;
    NSArray *keys = [NSArray arrayWithObjects: NSLocalizedDescriptionKey, NSLocalizedRecoverySuggestionErrorKey, nil];
    NSArray *values = [NSArray arrayWithObjects:description, recoverySuggestion, nil];
    NSDictionary *userDict = [NSDictionary dictionaryWithObjects:values forKeys:keys];
    *anError = [[NSError alloc] initWithDomain:@"my domain" code:errorCode userInfo:userDict];
    return NO;
}
*anError = [[NSError alloc] initWithDomain:@"my domain" code:errorCode userInfo:userDict];编译器给出下一个泄漏警告
“潜在的空取消引用。根据“创建和返回NSError对象”中的编码标准,参数“可以为空”
如何解决这个问题?

最佳答案

这实际上不是泄漏警告,而是对空指针的潜在取消引用。编译器抱怨这行

*anError = [[NSError alloc] initWithDomain:@"my domain" code:errorCode userInfo:userDict];

您无需检查anError实际上是否为空指针即可将其分配给anError指向的位置(“根据编码标准”是允许的,如果调用者对详细的错误信息不感兴趣,则可能会发生)。

10-06 02:33