ARC的指针转换 [英] Pointer casting with ARC
本文介绍了ARC的指针转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
ARC在执行以下强制转换时给了我很大的麻烦:
ARC is giving me a hard time with following cast:
NSDictionary *attributes;
SecItemCopyMatching((__bridge CFDictionaryRef)keychainItemQuery, (CFTypeRef *)&attributes);
错误:使用ARC不允许将间接指针强制转换为指向'CFTypeRef '(也称为'const void * ')的Objective-C指针
Error: Cast of an indirect pointer to an Objective-C pointer to 'CFTypeRef ' (aka 'const void *') is disallowed with ARC
推荐答案
问题是属性不应该是字典,而应该是SecKeyRef或CFDataRef.然后将其投射回NSData中,以获取复制到其中的密码数据.
The problem is that attributes shouldn't be a dictionary, it should be a SecKeyRef or CFDataRef. And then cast that back into NSData for the password data copied into it.
像这样:
CFDataRef attributes;
SecItemCopyMatching((__bridge CFDictionaryRef)keychainItemQuery, (CFTypeRef *)&attributes);
NSData *passDat = (__bridge_transfer NSData *)attributes;
这篇关于ARC的指针转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文