Note that there are some explanatory texts on larger screens.

plurals
  1. POnsexpression with custom function core data
    text
    copied!<p>i'm trying to group and count on date on a core data entity. since date cant be group due to different time. so i'm trying to pass custom function to nsexpression. but i get some errors i dont know what's the correct way to do it.</p> <p>code for grouping and counting:</p> <pre><code>NSEntityDescription *entity = [NSEntityDescription entityForName:@"TEvents" inManagedObjectContext:context]; NSDictionary *props = [entity propertiesByName]; NSPropertyDescription *propDesc3 = [props objectForKey:@"startDateTime"]; NSExpression *propExpr3 = [NSExpression expressionForKeyPath:@"startDateTime"]; NSExpression *countExpr3 = [NSExpression expressionForFunction:propExpr3 selectorName:@"dateShort" arguments:nil]; NSExpressionDescription *exprDesc3 = [[NSExpressionDescription alloc] init]; [exprDesc3 setExpression:countExpr3]; [exprDesc3 setExpressionResultType:NSDateAttributeType]; [exprDesc3 setName:@"dateStart"]; NSFetchRequest *fr = [NSFetchRequest fetchRequestWithEntityName:@"TEvents"]; [fr setPropertiesToGroupBy:[NSArray arrayWithObjects:propDesc3, nil]]; [fr setPropertiesToFetch:[NSArray arrayWithObjects:propDesc3, exprDesc3, nil]]; [fr setResultType:NSDictionaryResultType]; NSError * error = nil; NSArray *results = [context executeFetchRequest:fr error:&amp;error]; </code></pre> <p>dateShort is a nsdate category function which converts datatime to user's current zone:</p> <pre><code>-(NSString *) dateShort { NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setCalendar:[NSCalendar currentCalendar]]; [formatter setTimeZone:[NSTimeZone localTimeZone]]; [formatter setDoesRelativeDateFormatting:YES]; [formatter setDateStyle:NSDateFormatterShortStyle]; [formatter setTimeStyle:NSDateFormatterNoStyle]; NSString *tmpValue = [formatter stringFromDate:self]; return tmpValue; } </code></pre> <p>error:</p> <blockquote> <p>Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unsupported function type passed to SQL store'</p> </blockquote> <p>how to achieve this goal: convert datetime to current zone and group and count on (yy-mm-dd) on a core data entity?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload