在ARC上使用CFTypeRef遇到错误 [英] Getting error using CFTypeRef with ARC
本文介绍了在ARC上使用CFTypeRef遇到错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我基本上遵循了本教程,并很快意识到该项目由于我使用ARC而无法编译.我设法使用__bridge
(>.>)抑制了所有错误,但是我仍然收到一条错误消息,并且我设法读取了
I basically followed this tutorial, and soon realized the project wouldn't compile because I was using ARC. I managed to suppress all the errors using __bridge
(>.>) but I am still getting one error message, and I managed to read this stack question, but didn't understand how to apply the resolution to my problem.
基本上,给我带来问题的方法是这样的:
Basically the method that is giving me the problem looks like this:
+ (NSString*)getPasswordForKey:(NSString*)aKey
{
NSString *password = nil;
NSMutableDictionary *searchDictionary = [self dictionaryForKey:aKey];
[searchDictionary setObject:(__bridge id)kSecMatchLimitOne forKey:(__bridge id)kSecMatchLimit];
[searchDictionary setObject:(id)kCFBooleanTrue forKey:(__bridge id)kSecReturnData];
NSData *result = nil;
SecItemCopyMatching((__bridge CFDictionaryRef)searchDictionary, (CFTypeRef *)&result);
if (result)
{
password = [[NSString alloc] initWithData:result encoding:NSUTF8StringEncoding];
}
return password;
}
推荐答案
我认为您通过尝试强制转换指针到指针参数来进行不必要的复杂类型转换.怎么样:
I think you are making unnecessarily complex type casts by trying to cast the pointer-to-pointer argument. How about this:
CFTypeRef result = NULL;
BOOL statusCode = SecItemCopyMatching((__bridge CFDictionaryRef)searchDictionary, &result);
if (statusCode == errSecSuccess) {
NSData *resultData = CFBridgingRelease(result);
password = [[NSString alloc] initWithData:resultData encoding:NSUTF8StringEncoding];
}
这篇关于在ARC上使用CFTypeRef遇到错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文