小编Vin*_*nzo的帖子

将目标c中的4行代码转换为swift(指针)

自从两天将一段代码从Objective-C翻译成Swift以来,我一直陷入困境:

CFArrayRef keyref = NULL;
CFDictionaryRef identityDict = CFArrayGetValueAtIndex(keyref, 0);
SecIdentityRef identityRef = (SecIdentityRef)CFDictionaryGetValue(identityDict,      kSecImportItemIdentity);
Run Code Online (Sandbox Code Playgroud)

是的,就是这样!我根本无法用这些指针来满足编译器.请帮忙 :-)

这是要翻译的整个目标c代码:

// Read .p12 file
NSString *path = [[NSBundle mainBundle] pathForResource:@"SSLKeyStoreClient" ofType:@"p12"];
NSData *pkcs12data = [[NSData alloc] initWithContentsOfFile:path];

// Import .p12 data
CFArrayRef keyref = NULL;
OSStatus sanityChesk = SecPKCS12Import((__bridge CFDataRef)pkcs12data,
                                       (__bridge CFDictionaryRef)[NSDictionary
                                                                  dictionaryWithObject:@"wed-zzz"
                                                                  forKey:(__bridge id)kSecImportExportPassphrase],
                                       &keyref);
if (sanityChesk != noErr) {
    NSLog(@"Error while importing pkcs12 [%d]", (int)sanityChesk);
} else
    NSLog(@"Success opening p12 certificate.");

// Identity
CFDictionaryRef identityDict = CFArrayGetValueAtIndex(keyref, 0);
SecIdentityRef identityRef …
Run Code Online (Sandbox Code Playgroud)

pointers objective-c ios swift

6
推荐指数
1
解决办法
5829
查看次数

标签 统计

ios ×1

objective-c ×1

pointers ×1

swift ×1