ARC类型转换会导致编译器错误

时间:2012-09-05 11:16:37

标签: ios automatic-ref-counting type-conversion

我在ARC环境中遇到类型转换问题。如果有人也愿意解决它:

当我使用这行代码时:

OSStatus status = SecItemCopyMatching((CFDictionaryRef) CFBridgingRetain(attributeQuery), (CFTypeRef*)&attributeResult);

然后我有错误:

cast of an indirect pointer to an objective C pointer to 'CFTypeRef *' is disallowed with ARC.

请建议我以任何方式来解决这个问题。 提前谢谢..

1 个答案:

答案 0 :(得分:2)

问题是您使用的是NSDictionary for attributeResult而不是CFDictionary。试试这个,它应该工作(我使用相同的代码):

CFMutableDictionaryRef outDictionary = NULL;
if (!SecItemCopyMatching((__bridge CFDictionaryRef)tempQuery, (CFTypeRef *)&outDictionary) == noErr)
...
} else {
  // load the saved data from Keychain.
  keychainItemData = [self secItemFormatToDictionary:(__bridge NSDictionary *)outDictionary];
}
if(outDictionary) CFRelease(outDictionary);