I am creating a PDF file that consists of multiple screenshot, but I am facing a problem while extracting images from multiple views. I have a mutable Array which consist of views from a view controller named as "pdfViews"
var pdfViews : NSMutableArray = NSMutableArray()
and then I am adding view
self.pdfViews.addObject(generateAllComponents(kpiName))
The generateAllComponenets(:)
method creates an object of the required view controller and returns the view of that view controller.
And finally I try to convert these views into images and put those images inside an array.
for var i = 0 ; i < pdfViews.count; i++
{
var currentView = pdfViews.objectAtIndex(i) as! UIView
UIGraphicsBeginImageContext(currentView.frame.size)
currentView.layer.renderInContext(UIGraphicsGetCurrentContext())
UIGraphicsPushContext(UIGraphicsGetCurrentContext())
var image = UIGraphicsGetImageFromCurrentImageContext() as UIImage
tempImageArray.addObject(image);
}
It throws an EXC_BAD_ACCESS error. But if I pass only one view i.e, if pdfViews
has only 1 object then it works absolutely fine. But whenever I go with two objects in the pdfViews
mutable array, it shows an error like this:
The Views to be added in pdfViews mutable array also fetches some data from server.
Plus when I tried pass an array of UIImageViews
as pdfViews
it also worked fine.
But whenever I go with an array of views it throws this error.
Thanks in advance.