ios – Swift takeRetainedValue() and takeUnretainedValue() each EXC_BAD_ACCESS


I’ve objc perform that return SecIdentityRef

+ (SecIdentityRef)getSecIdentity {
NSString *resourcePath = [[NSBundle mainBundle] pathForResource:@"cert1" ofType:@"p12"];
NSData *p12Data = [NSData dataWithContentsOfFile:resourcePath];
NSMutableDictionary * choices = [[NSMutableDictionary alloc] init];

[options setObject:@"123456" forKey:(id)kSecImportExportPassphrase];

CFArrayRef objects = CFArrayCreate(NULL, 0, 0, NULL);

OSStatus securityError = SecPKCS12Import((CFDataRef) p12Data,
                                         (CFDictionaryRef)choices, &objects);

if (securityError == noErr && CFArrayGetCount(objects) > 0) {
    CFDictionaryRef identityDict = CFArrayGetValueAtIndex(objects, 0);
    SecIdentityRef identityApp =
    (SecIdentityRef)CFDictionaryGetValue(identityDict,
                                         kSecImportItemIdentity);
    CFRelease(objects);
    return identityApp;
}

CFRelease(objects);
return NULL;
}

I import class with this perform in bridging header, then use it in swift code

let check = Certificates.getSecIdentity()
let secIdentity = check.takeUnretainedValue()

From Certificates.getSecIdentity() returns Unmanaged<SecIdentityRef> with appropriate (?) SecIdentity inside.

On check.takeUnretainedValue() (and check.takeRetainedValue()) I obtain
Thread 1: EXC_BAD_ACCESS (code=1, handle=0x2d13e474f3e0)

What I do incorrect? How can I get SecIdentity?