Hi there
Can someone explain me why this code forces the processor into overdrive indefinitly?
If I don't do it in a queue, the processor does not go in overdrive.
Can someone explain me why this code forces the processor into overdrive indefinitly?
Code:
func addGalleryPhotoToCoreDataFromImage(image: UIImage) {
dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0)) { () -> Void in
// create a thumbnail and a smaller photo
let thumbnailImage = self.resizeImage(image, targetSize: CGSizeMake(167, 167))
let screenSize : CGSize = UIScreen.mainScreen().bounds.size
let bigImage = self.resizeImage(image, targetSize: CGSizeMake(screenSize.width, screenSize.height))
// save thumbnail and photo to CoreData
let newPhoto = NSEntityDescription.insertNewObjectForEntityForName("Photo", inManagedObjectContext: self.managedObjectContext!) as! Photo
newPhoto.thumbnail = UIImageJPEGRepresentation(thumbnailImage, 0.1)
newPhoto.photo = UIImageJPEGRepresentation(bigImage, 0.9)
self.photoSet!.addObject(newPhoto)
self.saveToCoreData()
dispatch_async(dispatch_get_main_queue(), { () -> Void in
self.refreshItemsInGalleryCollectionView()
})
}
}
If I don't do it in a queue, the processor does not go in overdrive.