I have the following code:
OSStatus status = SecItemCopyMatching((__bridge CFDictionaryRef)attrDictionary, (CFTypeRef *)&value);
which causes an error of:
Implicit conversion of an indirect pointer to an Objective-C pointer to 'CFTypeRef *' (aka 'const void **') is disallowed with ARC
Any idea on how to fix this? I have tried changing CFTypeRef *
to an id *
but it didn't work out
Here's the full method:
+ (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];
}
You can just cast it to void *
:
OSStatus status = SecItemCopyMatching((__bridge CFDictionaryRef)attrDictionary,
(void *)&value);
If you're using Objective-C++ you probably have to cast it twice:
OSStatus status = SecItemCopyMatching((__bridge CFDictionaryRef)attrDictionary,
(CFTypeRef *)(void *)&value);
Or you can use a temporary variable:
CFTypeRef cfValue = NULL;
OSStatus status = SecItemCopyMatching((__bridge CFDictionaryRef)attrDictionary, &cfValue);
NSData *value = (__bridge id)cfValue;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With