0

I use a custom UICollectionView to display iPhone's photos. I want to reload UICollectionView when app become active after user delete/modify/add one or more photos.

I save PHAsset in a array, [previousAssetsArray isEqual:currentAssetsArray] is not working.

Any idea?

EDIT:

What is the NSObject isEqual: and hash default function?

When I get photos' assets again, its address changed, so previousAsset will not equal to currentAsset even they belong to a photo. [previousAsset isEqual: currentAsset] always NO.

I also use the property hash of PHAsset to check if photos changed. But I found when I just modified(crop) one photo in Photos app, its hash not changed.

Community
  • 1
  • 1
tomfriwel
  • 2,575
  • 3
  • 20
  • 47
  • you can compare count values for both "previousAssetsArray" and "isEqual:currentAssetsArray" rather than comparing two arrays. – Hiren Patel Mar 30 '17 at 09:12
  • @HirenPatel If just modified some photos, I will reload `UICollectionView`, to compare count values will be not working. – tomfriwel Mar 30 '17 at 09:22
  • both arrays can have different memory addresses so you can't compare directly. You may have to iterate through array to compare changes or you have to reload collection view overtime app becomes active. – Hiren Patel Mar 30 '17 at 09:27
  • why don't you reload itself irrespective they are same or not? – Fahim Parkar Mar 30 '17 at 10:01
  • @FahimParkar Because when I reload it even there is nothing changed, reload `UICollectionView ` will cause some animation. That‘s not a good experience. – tomfriwel Mar 30 '17 at 10:07

1 Answers1

0

try this [previousAssetsArray isEqualToArray:currentAssetsArray]

Example:: BOOL theyAreEqual = [myFirstArray isEqualToArray:mySecondArray];

if you want to compare count of both array previousAssetsArray.count == currentAssetsArray .count

Shaik Thuphel
  • 75
  • 2
  • 10
  • It seems `PHAsset` can't compare, even is same photo's `PHAsset`. So `isEqualToArray` is not work. If array's objects is string, this method will be work. – tomfriwel Mar 30 '17 at 09:58
  • try this once. for ( int i = 0; i < [previousAssetsArray count]; i++ ) { if ( previousAssetsArray[i] == currentAssetsArray[i] ) { NSLog(@"the same elements in this selection"); } } – Shaik Thuphel Mar 30 '17 at 10:06
  • Because I get photos' `PHAsset` again, so `previousAsset` is not equal to `currentAsset` even they belong to one photo. If array's objects is `NSString`, this method is OK. – tomfriwel Apr 10 '17 at 08:47