0

The following code throws an NSInvalidArgumentException on the call to fetchAssetsWithOptions:

PHFetchOptions *allPhotosOptions = [[PHFetchOptions alloc] init];
allPhotosOptions.sortDescriptors =
        @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:NO]];
allPhotosOptions.predicate = 
        [NSPredicate predicateWithFormat:@"pixelHeight >=  pixelWidth * 1.95" ];
self.allPhotos = [PHAsset fetchAssetsWithOptions:allPhotosOptions];

The message is

NSInvalidArgumentException ... reason: '*** -constantValue only defined for abstract class.  
    Define -[NSFunctionExpression constantValue]!'

I tried numerous variations on the predicate format string, but always get this message when I try to use multiplication. What am I doing wrong?

Alan M
  • 98
  • 8

1 Answers1

0

I'm not certain why, but when you don't pass any format arguments to predicateWithFormat: and use it with Photos you get this error;

I was able to fix the issue by ensuring I was passing format arguments. So in your case:

float heightLimit = pixelWidth * 1.95;
[NSPredicate predicateWithFormat:@"pixelHeight >= %f", heightLimit];
kball
  • 4,923
  • 3
  • 29
  • 31