Swift setAnchorCert example?

Does anyone have an example of using the CBLReplication setAnchorCert method in Swift they could share?

Swift + setAnchorCert example?

Is that a no?

No - examples?
No - not in Swift?

Anyone? Anyone?

Okay. So I’m answering my own question so as to help others.

Tricks.

  • Your certificate needs to be in der format, and stored in your project bundle.
  • You need to ensure you include the certificate file as part of your project Copy Bundle Resources options.

This code is “base code” - you’ll need to add error checking etc.

let certificateFileName = "data" let certificatePath = NSBundle.mainBundle().pathForResource(certificateFileName, ofType: "der") let certificateData = NSData(contentsOfFile: certificatePath!) let certificate = SecCertificateCreateWithData(nil, certificateData!) CBLReplication.setAnchorCerts([certificate as! AnyObject], onlyThese: true)