IOS: CFTypeRef prohibited by ARC

I want to get the username / password from my keychain. for this i followed this guide:

Easy Keychain Access for iPhone

But this part is not allowed using ARC:

NSData *result = nil; OSStatus status = SecItemCopyMatching( (CFDictionaryRef)searchDictionary, (CFTypeRef *)&result); 

What can I do?

+7
source share
2 answers

ARC only manages Objective-C types. If you use Core Foundation types, you need to specify the ARC to which this variable belongs, using __bridge , __bridge_retained or __bridge_transfer .

Here's Apple 's official documentation on free ARC bridging, or see this blog post (scroll down to Toll-Free Bridging) for a great overview.

For example:

 NSData *inData = nil; CFTypeRef inTypeRef = (__bridge CFTypeRef)inData; OSStatus status = SecItemCopyMatching( (__bridge CFDictionaryRef)searchDictionary, &inTypeRef); 
+19
source
 CFTypeRef inData = NULL; OSStatus status = SecItemCopyMatching( (__bridge CFDictionaryRef)searchDictionary, & inData); NSData *data = (__bridge NSData *)inData; 
+1
source

All Articles