Skip to content

Commit

Permalink
[eBay#143] added PHAssets delegate methods for multiselect picker
Browse files Browse the repository at this point in the history
also using `defer` keyrowd for safer `imageListGuard.unlock`
  • Loading branch information
Alexander Dodatko committed Jul 20, 2017
1 parent 74722aa commit 6a355a3
Showing 1 changed file with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ open class MultiselectImagePicker: UIViewController
private func performSave()
{
let loaders = self._controller.imageLoadersForSelectedImages()
let assets = self._controller.assetsForSelectedImages()

self.loadedImages = []

// TODO: maybe move group and mutex to ivars
Expand All @@ -104,29 +106,41 @@ open class MultiselectImagePicker: UIViewController
[weak weakSelf = self]
(maybeImage, _) in

defer
{
group.leave()
}

if let singleImage = maybeImage
{
imageListGuard.lock()
defer
{
imageListGuard.unlock()
}

weakSelf?.loadedImages.append(singleImage)
imageListGuard.unlock()
}

group.leave()
}
singleLoader(loaderCallback)
}

group.notify(queue: DispatchQueue.main)
{
self.performSave(withImages: self.loadedImages)
self.performSave(
withImages: self.loadedImages,
assets: assets)
}
}

private func performSave(withImages images: [UIImage])
private func performSave(
withImages images: [UIImage],
assets: [PHAsset])
{
// popping current controller will be made by NMessengerBarView
//
self.cameraDelegate?.pickedImages(images)
self.cameraDelegate?.pickedImageAssets(assets)
}

private func addGridViewFullScreen()
Expand Down

0 comments on commit 6a355a3

Please sign in to comment.