Type conversion causing compilation error in ARC environment

I have a type conversion problem in the ARC environment. If someone is kind enough to address him:

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 get the error message:

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.

+6
source share
1 answer

The result data type is just CFTypeRef until the SecItemCopyMatching call begins, passing to CFTypeRef :

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

Since the request indicated that resultData should be CFDataRef , resultData now CFDataRef , and now you can use it as such. then add it further to NSData .

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

Or in one line:

 NSData *resultNSData = (__bridge NSData *)(CFDataRef)resultData; 
+5
source

Source: https://habr.com/ru/post/924894/


All Articles