botptr
botptr

Reputation: 977

Trouble with CoreData and finding date

I have a simple model, that represents Days meals and training sessions. I am having an issue with getting the Day from CoreData. I get the following error.

2011-11-14 11:41:44.999 CalorificCounter[21002:fb03] -[__NSCFString timeIntervalSinceReferenceDate]: unrecognized selector sent to instance 0x6a6d1a0
2011-11-14 11:41:45.001 CalorificCounter[21002:fb03] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString timeIntervalSinceReferenceDate]: unrecognized selector sent to instance 0x6a6d1a0'

Code

-(Day *)getDayForDate:(NSDate *)date
{
    Day *day;
    date = [self dateAtStartOfDay:date];

    NSFetchRequest *request = [[NSFetchRequest alloc]init];
    NSEntityDescription *entity = [NSEntityDescription entityForName:@"Day" 
                                        inManagedObjectContext:[self managedObjectContext]];

    //Find the object that matches the given date from a predicate
    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"date == \"%@\"",date];


    [request setEntity:entity];
    [request setPredicate:predicate];

    //Try to fetch
    NSError *error;
    NSArray *result = [[self managedObjectContext] executeFetchRequest:request 
                                                             error:&error ] ;

The error occurs on the execution of the fetch request. I have traced execution and everything seems to be the correct type (at least I am never passing a string around). Thanks in advance.

UPDATE Dont put the predicated date in quotes

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"date == %@",date];

Upvotes: 2

Views: 811

Answers (1)

Lahiru Pinto
Lahiru Pinto

Reputation: 1681

This issue occur when you have assign a String to the date object. Check the date value and return a NSDate object

Upvotes: 0

Related Questions