I want to find duplicated photos/videos in photo library and delete them. But I got confused how can I compare all photos to each other and find which of them are duplicated.
Comparing bytes is not useful, which way should I take?
Using the Photos framework you can get a list of all media using the following
PHPhotoLibrary.requestAuthorization { status in
if status == .authorized {
let fetchOptions = PHFetchOptions()
fetchOptions.sortDescriptors = [NSSortDescriptor(key:"creationDate", ascending:true)]
assets = PHAsset.fetchAssets(with: fetchOptions)
}
}
The code above orders the assets by creation date. That means when checking through your list of 5000 odd assets you only need to check neighboring assets in the list to see if they are duplicates.