【发布时间】:2013-08-26 08:10:05
【问题描述】:
我有一个entity,其中包含具有NSDate (format yyyy-MM-dd) 的对象现在我想做一个fetch request,只包含今天具有NSDate 的对象。所以我正在做以下事情。
NSDate *now = [NSDate new];
RKManagedObjectStore *store = [[DominoDataModel sharedDataModel] objectStore];
NSManagedObjectContext *context = store.mainQueueManagedObjectContext;
NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:@"Event"];
NSPredicate *predicate = [NSPredicate predicateWithFormat:
@"eve_date = %@",now];
fetchRequest.predicate = predicate;
NSSortDescriptor *descriptor = [NSSortDescriptor sortDescriptorWithKey:@"eve_date" ascending:YES];
fetchRequest.sortDescriptors = @[descriptor];
NSArray *matches = [context executeFetchRequest:fetchRequest error:nil];
arrConcerten = [matches mutableCopy];
NSLog(@"matches %@",matches);
我的NSLog 总是不返回匹配项。
有人可以帮我吗?
编辑
我的实体包含这样的 NSDates:
2013/08/29
2013/08/30
2013/09/02
2013/09/15
2013/09/28
我以为我可以将这些 NSDate 与今天的日期进行比较?但这可能不起作用,因为我实体中的 NSDates 没有时间戳?
【问题讨论】:
-
没有“格式”的
NSDate。eve_date属性中的值究竟是什么? -
这不是(几乎)与您上一个问题stackoverflow.com/questions/18332769/…中的问题相同吗? - 你必须与“一天的开始”和“第二天的开始”进行比较。
-
@CarlVeazey 我已经编辑了我的问题
-
这看起来不像是格式化日期字符串的
NSDate。当您查看底层持久存储时,您会发现什么值?或者,您如何在代码中填充这些日期?
标签: iphone ios objective-c nsdate nsfetchrequest