I'm trying to connect openssl s_server
and iOS client using TCP SSL(also, I get another issue with this, maybe this related). Now I'm trying to use this sample code from github for this:
let mainbun = NSBundle.mainBundle().pathForResource("pd-test", ofType: "cer")
var key: NSData = NSData.dataWithContentsOfMappedFile(mainbun!)! as NSData
var cert:SecCertificateRef =
SecCertificateCreateWithData(kCFAllocatorDefault, key).takeRetainedValue()
var err:OSStatus = noErr
let secDict = NSDictionary(
objects: [kSecClassCertificate,cert],
forKeys: [kSecClass, kSecValueRef]
)
SecItemAdd(secDict as CFDictionaryRef, nil);
But get errors:
ViewController.swift:67:74: 'AnyObject' is not convertible to 'NSData'; did you mean to use 'as!' to force downcast?
ViewController.swift:69:9: Value of type 'SecCertificate?' has no member 'takeRetainedValue'
ViewController.swift:75:23: Value of type 'CFString' does not conform to expected element type 'NSCopying'
Why I can't build valid code(I saw many samples like this, all they throw almost the same errors, e.g. this)? How can I fix it?