谓词根据关系查找核心数据父对象

时间:2018-11-10 13:23:56

标签: ios core-data predicate

我正在尝试使用谓词基于与子对象(事务)的关系来查找父对象(库)。我已经反向使用类似的代码来查找银行的交易没有问题,但是之前从未尝试过反向使用它。该事务是从以前的vc传递的,并且显示正确。同样,我的[_banksListData count]正确显示了几个存储库,但在谓词显示为0之后。

Obj c或Swift中的任何建议或代码都非常感谢

这是我的代码-

//search banks for relationship with transaction
_banksListData = [CoreDataHelper getObjectsForEntity:@"Banks" withSortKey:@"name" andSortAscending:YES andContext:_managedObjectContext];
NSLog(@"banks count: %lu", (unsigned long)[_banksListData count]);

// banks count ok

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

NSLog(@"bankForTransaction count: %lu", (unsigned long)([[_banksListData filteredArrayUsingPredicate:predicate] count]));

//after predicate- count is 0!!!! Why!!!!

if([[_banksListData filteredArrayUsingPredicate:predicate] count]>0)
  _bank = [[_banksListData filteredArrayUsingPredicate:predicate] objectAtIndex:0];
NSLog(@"transaction is for account: %@", _bank.name);

0 个答案:

没有答案