Note that there are some explanatory texts on larger screens.

plurals
  1. POcoredata filtering by date using NSPredicate returns nothing
    primarykey
    data
    text
    <p>Hi i am new to this coredata. I have two entities CategoryList and ExpenseList. CategoryList consists of two attributes<br> 1.dates (nsdate)<br> 2.categories (nsstring)<br> and in to many relation with ExpenseList, relationship name is "expenseList" ExpenseList consists of 1.amountSpent (float).<br> I just wanted to know learn about relationship features in coredata. When i tried to create a nspredicate to filter the data by a specific date, its returning nothing. I just wanted to filter the categories attribute content in the CategoryList entity for a specific date. Here is my code</p> <pre><code>-(void) callingByDate { NSManagedObjectContext *managedObjectContext = [self managedObjectContext]; NSEntityDescription *categoryL = [NSEntityDescription entityForName:@"CategoryList" inManagedObjectContext:managedObjectContext]; NSSortDescriptor *dateSort = [[NSSortDescriptor alloc]initWithKey:@"date" ascending:YES]; NSArray *sortDescriptors = [[NSArray alloc]initWithObjects:dateSort, nil]; NSPredicate *predicate = [NSPredicate predicateWithFormat:@"dates == %@",date]; NSFetchRequest *dateFetch = [[NSFetchRequest alloc]init]; [dateFetch setSortDescriptors:sortDescriptors]; [dateFetch setEntity:categoryL]; [dateFetch setPredicate:predicate]; NSMutableArray *results = [[managedObjectContext executeFetchRequest:dateFetch error:nil] mutableCopy]; if([results count] &gt; 0) NSLog(@"results found"); else NSLog(@"no results found"); } </code></pre> <p>when i execute this code in the nslog area its showing 'no results found'. I could not figure out why . Thanks in advance</p> <p>here is my code to find the end and start of the day</p> <pre><code>-(NSDate *)beginningOfDay:(NSDate *)date; { NSDate *dat = [NSDate date]; NSCalendar *cal = [NSCalendar currentCalendar]; NSDateComponents *components = [cal components:( NSMonthCalendarUnit | NSYearCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit ) fromDate:dat]; [components setHour:0]; [components setMinute:0]; [components setSecond:0]; return [cal dateFromComponents:components]; } -(NSDate *)endOfDay:(NSDate *)date; { NSDate *dat = [NSDate date]; NSCalendar *cal = [NSCalendar currentCalendar]; NSDateComponents *components = [cal components:( NSMonthCalendarUnit | NSYearCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit ) fromDate:dat]; [components setHour:23]; [components setMinute:59]; [components setSecond:59]; return [cal dateFromComponents:components]; </code></pre> <p>when i nslog, the result showing is startday -2013-04-30 18:30:00 +0000 endOfDay -2013-05-01 18:29:59 +0000</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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