Pointer casting with ARC

前端 未结 3 1573
一生所求
一生所求 2021-02-03 22:32

ARC is giving me a hard time with following cast:

NSDictionary *attributes;
SecItemCopyMatching((__bridge CFDictionaryRef)keychainItemQuery, (CFTypeRef *)&at         


        
3条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-03 22:40

    The problem is that attributes shouldn't be a dictionary, it should be a SecKeyRef or CFDataRef. And then cast that back into NSData for the password data copied into it.

    Like so:

    CFDataRef attributes;
    SecItemCopyMatching((__bridge CFDictionaryRef)keychainItemQuery, (CFTypeRef *)&attributes);
    NSData *passDat = (__bridge_transfer NSData *)attributes;
    

提交回复
热议问题