2012-09-13 14 views
9

Tengo el siguiente código:elenco de puntero indirecto a un puntero de Objective-C

OSStatus status = SecItemCopyMatching((__bridge CFDictionaryRef)attrDictionary, (CFTypeRef *)&value); 

lo que provoca un error de:

Implicit conversion of an indirect pointer to an Objective-C pointer to 'CFTypeRef *' (aka 'const void **') is disallowed with ARC 

Cualquier idea sobre cómo solucionar este problema? He intentado cambiar a un CFTypeRef *id * pero no funcionó

Aquí está el método completo:

+ (NSData *)keychainValueForKey:(NSString *)key { 
    if (key == nil) { 
    return nil; 
    } 

    NSMutableDictionary *attrDictionary = [self attributesDictionaryForKey:key]; 

    // Only want one match 
    [attrDictionary setObject:(id)kSecMatchLimitOne forKey:(id)kSecMatchLimit]; 

    // Only one value being searched only need a bool to tell us if it was successful 
    [attrDictionary setObject:(id)kCFBooleanTrue forKey:(id)kSecReturnData]; 

    NSData *value = nil; 
    OSStatus status = SecItemCopyMatching((CFDictionaryRef)attrDictionary, (CFTypeRef *)&value); 
    if (status != errSecSuccess) { 
    DLog(@"KeychainUtils keychainValueForKey: - Error finding keychain value for key. Status code = %d", status); 
    } 
    return [value autorelease]; 
} 

Respuesta

27

Usted puede simplemente echarlo a void *:

OSStatus status = SecItemCopyMatching((__bridge CFDictionaryRef)attrDictionary, 
    (void *)&value); 

Si eres usando Objective-C++ probablemente tenga que lanzarlo dos veces:

OSStatus status = SecItemCopyMatching((__bridge CFDictionaryRef)attrDictionary, 
    (CFTypeRef *)(void *)&value); 

O puede usar una variable temporal:

CFTypeRef cfValue = NULL; 
OSStatus status = SecItemCopyMatching((__bridge CFDictionaryRef)attrDictionary, &cfValue); 
NSData *value = (__bridge id)cfValue; 
Cuestiones relacionadas