1

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;
} 
Community
  • 1
  • 1
ipatch
  • 3,933
  • 8
  • 60
  • 99

1 Answers1

4

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];
}
Ole Begemann
  • 135,006
  • 31
  • 278
  • 256
  • I tried the code you typed above but now I am getting an error on the line: `NSData *resultData = CFBridgingRelease(result);` The error message I am getting is: Implicit conversion of int into NSData is disallowed with ARC – ipatch Jun 13 '12 at 20:37
  • I had a lower case `f` for CFBridgingRelease (>.>) – ipatch Jun 14 '12 at 06:25