Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cast of indirect pointer to an Objective-C pointer

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];
}
like image 459
adit Avatar asked Sep 13 '12 18:09

adit


1 Answers

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;
like image 163
rob mayoff Avatar answered Oct 14 '22 10:10

rob mayoff