6

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

当我使用这行代码时:

NSData *resultData = nil;

NSMutableDictionary *passwordQuery = [query mutableCopy];

[passwordQuery setObject: (id) kCFBooleanTrue forKey: (__bridge  id) kSecReturnData];

status = SecItemCopyMatching((__bridge  CFDictionaryRef) passwordQuery, (CFTypeRef *) &resultData);

然后我收到一个错误:

Cast of an indirect pointer to an Objective C pointer to 'CFTypeRef*'(aka 'const void **')is disallowed with ARC.

请建议我任何解决此问题的方法..

提前致谢..

4

1 回答 1

6

结果数据类型只是CFTypeRef在调用SecItemCopyMatchingso 之后的直到,通过传入 a 开始CFTypeRef

CFTypeRef resultData = nil;
status = SecItemCopyMatching((__bridge CFDictionaryRef) passwordQuery,  &resultData);

由于查询指定resultData应该是 aCFDataRef现在resultData是 a CFDataRef,因此您现在可以将其转换为这样。然后将其进一步转换为NSData.

CFDataRef resultCFData = (CFDataRef)resultData;
NSData *resultNSData = (__bridge NSData *)resultCFData;

或者在一行中:

NSData *resultNSData = (__bridge NSData *)(CFDataRef)resultData;
于 2012-09-11T18:45:38.440 回答