iosswift3cgpdfunsafemutablepointercgpdfscanner

Passing UnsafeMutablePointer to Ref Object in a function in swift 3


I'm developing a pdf parser in swift, so i've stumbled upon the function CGPDFScannerPopString which takes a CGPDFScannerRef and an UnsafeMutablePointer?

The Objective C code looks like this:

CGPDFStringRef pdfString;
CGPDFScannerPopString(pdfScanner, &pdfString);

How do I write this in swift 3?


Solution

  • The type of the second parameter of CGPDFScannerPopString is UnsafeMutablePointer<CGPDFStringRef?>?. So, you need to prepare a variable of type CGPDFStringRef? and pass it as an inout argument:

    var pdfString: CGPDFStringRef?
    _ = CGPDFScannerPopString(pdfScanner, &pdfString)