Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Type conversion causing compilation error in ARC environment

I am having a problem in type conversion in ARC environment.If anyone would be kind enough to address it as well:

When i used this line of code:

NSData *resultData = nil;

NSMutableDictionary *passwordQuery = [query mutableCopy];

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

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

Then i am recieving an error:

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

Please suggest me any way to ressolve this..

Thanks in advance..

like image 626
Vineet Singh Avatar asked Sep 08 '12 07:09

Vineet Singh


1 Answers

The result data type is merely a CFTypeRef until after the call to SecItemCopyMatching so start by passing in a CFTypeRef:

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

Since the query specified that the resultData should be a CFDataRef the resultData is now a CFDataRef, and you can now cast it as such. then cast it further into an NSData.

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

Or in one line:

NSData *resultNSData = (__bridge NSData *)(CFDataRef)resultData;
like image 197
Mr. Berna Avatar answered Sep 28 '22 02:09

Mr. Berna