Core Data @sum aggregate
Posted
by nasim
on Stack Overflow
See other posts from Stack Overflow
or by nasim
Published on 2010-05-31T14:01:01Z
Indexed on
2010/05/31
14:02 UTC
Read the original article
Hit count: 332
I am getting an exception when I try to get @sum on a column in iPhone Core-Data application.
My two models are following -
Task model:
@interface Task : NSManagedObject
{
}
@property (nonatomic, retain) NSString * taskName;
@property (nonatomic, retain) NSSet* completion;
@end
@interface Task (CoreDataGeneratedAccessors)
- (void)addCompletionObject:(NSManagedObject *)value;
- (void)removeCompletionObject:(NSManagedObject *)value;
- (void)addCompletion:(NSSet *)value;
- (void)removeCompletion:(NSSet *)value;
@end
Completion model:
@interface Completion : NSManagedObject
{
}
@property (nonatomic, retain) NSNumber * percentage;
@property (nonatomic, retain) NSDate * time;
@property (nonatomic, retain) Task * task;
@end
And here is the fetch:
NSFetchRequest *request = [[NSFetchRequest alloc] init];
request.entity = [NSEntityDescription entityForName:@"Task" inManagedObjectContext:context];
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"taskName" ascending:YES];
request.sortDescriptors = [NSArray arrayWithObject:sortDescriptor];
NSError *error;
NSArray *results = [context executeFetchRequest:request error:&error];
NSArray *parents = [results valueForKeyPath:@"taskName"];
NSArray *children = [results valueForKeyPath:@"[email protected]"];
NSLog(@"%@ %@", parents, children);
[request release];
[sortDescriptor release];
The exception is thrown at the fourth line from bottom. The thrown exception is:
*** -[NSCFSet decimalValue]: unrecognized selector sent to instance 0x3b25a30
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSCFSet decimalValue]: unrecognized selector sent to instance 0x3b25a30'
I would very much appreciate any kind of help. Thanks.
© Stack Overflow or respective owner