1

Actual query :-

SELECT *,COUNT(case when ZISREAD = 0 then ZISREAD end) FROM ZNOTIFICATION WHERE ZTTL>1411025900  group by zkind,zaction,zname

Hi, i need to convert the Count condition COUNT(case when ZISREAD = 0 then ZISREAD end)using core data NSExpression

 NSExpression *countPathExpression = [NSExpression expressionForKeyPath: @"isRead"];

 NSExpression *countExpression = [NSExpression expressionForFunction: @"count:"
                                                              arguments: [NSArray arrayWithObject:countPathExpression]];

    NSExpressionDescription *countExpressionDescription = [[NSExpressionDescription alloc] init];
    [countExpressionDescription setName: @"count"];
    [countExpressionDescription setExpression: countExpression];
    [countExpressionDescription setExpressionResultType: NSInteger32AttributeType];

i need Help guys to convert COUNT(case when ZISREAD = 0 then ZISREAD end) in NSExpression

Andi Domi
  • 731
  • 2
  • 19
  • 48
Hiren Panchal
  • 2,963
  • 1
  • 25
  • 21

1 Answers1

0

First things first you could add a predicate to your fetch request:

fetchRequest.predicate = [NSPredicate predicateWithFormat:@"isRead = NO"];

Then you want to specify your expression in properties to fetch:

fetchRequest.propertiesToFetch = @[countExpression];

Don't forget to set the result type

fetchRequest.resultType = NSDictionaryResultType;

That should get you going. Remember you can also use the propertiesToGroupBy array if you want to evaluate your expression across properties, an example would be to group by day, that would allow you to see the count per day:)

Happy coding

Daniel Galasko
  • 23,617
  • 8
  • 77
  • 97