My goal to achieve merge long files 500 mb to 1gb File. i have merged all files but the issue is Write a file but memory usage is very low then app crashed. Can you guide me how to cattle this problem.if i merged 46 files then some time show didReceiveLowWarning and some time app is crashed because virtual memory very low Kindly Help and my Code is
fileprivate func recursiveFunctionforMergeMultipleFiles(firstFile:URL,secondURl:URL,outputUrl:URL) -> URL
{
let filedocument1 = PDFDocument(url: firstFile)
let pdfdocument2 = PDFDocument(url: secondURl)
filedocument1?.addPages(from: pdfdocument2!)
filedocument1?.write(to: outputUrl)
return outputUrl
}
extension PDFDocument {
func addPages(from document: PDFDocument) {
let pageCountAddition = document.pageCount
for pageIndex in 0..<pageCountAddition {
guard let addPage = document.page(at: pageIndex) else {
break
}
self.insert(addPage, at: pageIndex) // unfortunately this is very very confusing. The index is the page *after* the insertion. Every normal programmer would assume insert at self.pageCount-1
}
}
}
i have tried multiple resource to merge but this one is best