簡體   English   中英

指向Objective-C指針的間接指針的強制轉換

[英]cast of indirect pointer to an Objective-C pointer

我有以下代碼:

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

這導致錯誤:

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

有關如何解決此問題的任何想法? 我已經嘗試將CFTypeRef *更改為id *但它沒有成功

這是完整的方法:

+ (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];
}

您可以將其void *void *

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

如果您使用的是Objective-C ++,則可能需要將其強制轉換兩次:

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

或者您可以使用臨時變量:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM