iosswift3cfpdfxcode8

Build time is too long in Xcode 8.3 with swift 3 in particular file


Im using Xcode 8.3 with Swift 3. I have written one method named pdfFromData(data:) to form the pdf document from the Data, whenever I build my project its not getting build due to this method, means the compiler is got stopped/hanged when it start compile particular file where I coded pdfFromData(data:) method(In Xcode 8.2 with Swift 3 it worked fine). Whenever i comment this method and build means everything working fine.

func pdfFromData(data: Data) -> CGPDFDocument? { // Form pdf document from the data.

    if let pdfData = data as? CFData {
        if let provider = CGDataProvider(data: pdfData) {
            let pdfDocument = CGPDFDocument(provider)
            return pdfDocument
        }
    }
    return nil

}

What's wrong with this method?. I want to build my project with this method as well. Thanks in advance.


Solution

  • I tried debugging your issue. This is what I found out:

    if let pdfData = data as? CFData {
    
    }
    

    The above line for casting object of type Data to CFData is where it's taking too much time to build.

    Replacing that with the following piece of code significantly reduces your build time.

    let pdfNsData: NSData = NSData(data: data) // convert `Data` to `NSData`
    
    if let cfPdfData: CFData = pdfNsData as? CFData { 
    // cast `NSData` to `CFData`
    
    }
    

    NSData and CFData are toll-free bridged.

    Please let me know if there's any doubt