class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate, PHPhotoLibraryChangeObserver <- 추가
// tableview에 스와이프 해서 delete 버튼 나오게 하는 메서드
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath)
{
print("시스템 : \(editingStyle)")
if editingStyle == .delete
{
let asset : PHAsset = self.fetch_result[indexPath.row]
PHPhotoLibrary.shared().performChanges({PHAssetChangeRequest.deleteAssets([asset] as NSArray)}, completionHandler: nil)
}
print("시스템 : editingStyle", #function)
}
//아이템이 삭제되고나면 제정렬 시키는 메서드
func photoLibraryDidChange(_ changeInstance: PHChange)
{
print("시스템 : ",#function)
guard let changes = changeInstance.changeDetails(for: fetch_result)
else
{
return
}
fetch_result = changes.fetchResultAfterChanges
OperationQueue.main.addOperation
{
self.table_view.reloadSections(IndexSet(0...0), with: .automatic)
}
}