我想通过for in
循环修改一些核心数据实体。应通过谓词过滤提取的对象。但是循环永远不会触发,因为没有提取任何对象。
我怀疑谓词存在问题,尽管我已经非常仔细地审查了它。这是代码:
NSString *replenishString = @"Replenishment";
NSDate *now = [NSDate date];
NSPredicate *transFRCPredicate = [NSPredicate predicateWithFormat:@"(account == %@) AND ((transDate >= %@) AND (transDate <= %@)) AND (category != %@)",self.detailTransaction.account,self.detailTransaction.transDate,now,replenishString];
NSFetchedResultsController *transactionsToAdjustFRC = [WMMGTransaction MR_fetchAllGroupedBy:@"account" withPredicate:transFRCPredicate sortedBy:@"transDate" ascending:NO];
(...)
for (WMMGTransaction *transaction in transactionsToAdjustFRC.fetchedObjects)
{
NSLog(@"Inside for loop--delta = %@",delta);
transaction.category = @"Changed +";
transaction.pointBalance = [transaction.pointBalance decimalNumberByAdding: delta];
NSLog(@"Inside for loop--pointBalance = %@",transaction.pointBalance);
}
任何想法或指导?
感谢名单!
答案 0 :(得分:1)
在谓词中使用“!=”时要小心:nil值不匹配。包括针对nil的特定测试:
NSPredicate *transFRCPredicate = [NSPredicate predicateWithFormat:@"(account == %@) AND ((transDate >= %@) AND (transDate <= %@)) AND (category != %@ OR category == nil)",self.detailTransaction.account,self.detailTransaction.transDate,now,replenishString];