Skip to content

Commit

Permalink
revert commit : compatible swift 4.0 compactMap -> flatMap
Browse files Browse the repository at this point in the history
  • Loading branch information
tilltue committed Jan 28, 2019
1 parent 6e7d50c commit c74b1d5
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion TLPhotoPicker.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'TLPhotoPicker'
s.version = '1.8.2'
s.version = '1.8.3'
s.summary = 'multiple phassets picker for iOS lib. like facebook'

# This description is used to generate tags and improve search results.
Expand Down
36 changes: 36 additions & 0 deletions TLPhotoPicker/Classes/TLPhotosPickerViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -425,10 +425,18 @@ extension TLPhotosPickerViewController {

private func dismiss(done: Bool) {
if done {
#if swift(>=4.1)
self.delegate?.dismissPhotoPicker(withPHAssets: self.selectedAssets.compactMap{ $0.phAsset })
#else
self.delegate?.dismissPhotoPicker(withPHAssets: self.selectedAssets.flatMap{ $0.phAsset })
#endif
self.delegate?.dismissPhotoPicker(withTLPHAssets: self.selectedAssets)
self.completionWithTLPHAssets?(self.selectedAssets)
#if swift(>=4.1)
self.completionWithPHAssets?(self.selectedAssets.compactMap{ $0.phAsset })
#else
self.completionWithPHAssets?(self.selectedAssets.flatMap{ $0.phAsset })
#endif
}else {
self.delegate?.photoPickerDidCancel()
self.didCancel?()
Expand Down Expand Up @@ -589,10 +597,17 @@ extension TLPhotosPickerViewController {
guard self.configure.autoPlay else { return }
guard self.playRequestId == nil else { return }
let visibleIndexPaths = self.collectionView.indexPathsForVisibleItems.sorted(by: { $0.row < $1.row })
#if swift(>=4.1)
let boundAssets = visibleIndexPaths.compactMap{ indexPath -> (IndexPath,TLPHAsset)? in
guard let asset = self.focusedCollection?.getTLAsset(at: indexPath), asset.phAsset?.mediaType == .video else { return nil }
return (indexPath,asset)
}
#else
let boundAssets = visibleIndexPaths.flatMap{ indexPath -> (IndexPath,TLPHAsset)? in
guard let asset = self.focusedCollection?.getTLAsset(at: indexPath.row),asset.phAsset?.mediaType == .video else { return nil }
return (indexPath,asset)
}
#endif
if let firstSelectedVideoAsset = (boundAssets.filter{ getSelectedAssets($0.1) != nil }.first) {
play(asset: firstSelectedVideoAsset)
}else if let firstVideoAsset = boundAssets.first {
Expand Down Expand Up @@ -663,6 +678,7 @@ extension TLPhotosPickerViewController: PHPhotoLibraryChangeObserver {
if changes.hasIncrementalChanges, self.configure.groupByFetch == nil {
var deletedSelectedAssets = false
var order = 0
#if swift(>=4.1)
self.selectedAssets = self.selectedAssets.enumerated().compactMap({ (offset,asset) -> TLPHAsset? in
var asset = asset
if let phAsset = asset.phAsset, changes.fetchResultAfterChanges.contains(phAsset) {
Expand All @@ -673,6 +689,18 @@ extension TLPhotosPickerViewController: PHPhotoLibraryChangeObserver {
deletedSelectedAssets = true
return nil
})
#else
self.selectedAssets = self.selectedAssets.enumerated().flatMap({ (offset,asset) -> TLPHAsset? in
var asset = asset
if let phAsset = asset.phAsset, changes.fetchResultAfterChanges.contains(phAsset) {
order += 1
asset.selectedOrder = order
return asset
}
deletedSelectedAssets = true
return nil
})
#endif
if deletedSelectedAssets {
self.focusedCollection?.fetchResult = changes.fetchResultAfterChanges
self.reloadCollectionView()
Expand Down Expand Up @@ -758,11 +786,19 @@ extension TLPhotosPickerViewController: UICollectionViewDelegate,UICollectionVie
//deselect
self.logDelegate?.deselectedPhoto(picker: self, at: indexPath.row)
self.selectedAssets.remove(at: index)
#if swift(>=4.1)
self.selectedAssets = self.selectedAssets.enumerated().compactMap({ (offset,asset) -> TLPHAsset? in
var asset = asset
asset.selectedOrder = offset + 1
return asset
})
#else
self.selectedAssets = self.selectedAssets.enumerated().flatMap({ (offset,asset) -> TLPHAsset? in
var asset = asset
asset.selectedOrder = offset + 1
return asset
})
#endif
cell.selectedAsset = false
cell.stopPlay()
self.orderUpdateCells()
Expand Down

0 comments on commit c74b1d5

Please sign in to comment.