Hello,
files is an array of File objects.
I want to enumerate through the file array and check for File objects that has equal md5 digest.
I want to remove the file objects from the array that are copies of currentFile, but I can't remove objects from the files array while it's enumerating. Can I achieve this by some other means?
files is an array of File objects.
I want to enumerate through the file array and check for File objects that has equal md5 digest.
I want to remove the file objects from the array that are copies of currentFile, but I can't remove objects from the files array while it's enumerating. Can I achieve this by some other means?
Code:
for (File *currentFile in files) {
NSPredicate *predicate = [NSPredicate predicateWithFormat: @"md5Hash == %@ && filePath != %@", [currentFile md5Hash], [currentFile filePath]]; // This will check for files that has equal md5 digest but not the same filepath (ie true if it's a file duplicate)
if ([[files filteredArrayUsingPredicate:predicate] count] > 0) // If copies are found
{
[currentFile addCopies:[files filteredArrayUsingPredicate:predicate]]; // The file class has an array which stores its copies
[files removeObjectsInArray:[files filteredArrayUsingPredicate:predicate]]; // Can't do this. :(
}
}