iphone - NSPredicate by NSManagedObject 用于多对一查找

标签 iphone cocoa cocoa-touch core-data predicate

我有两个 NSManagedObjects 的场景,Arm 和 Person。他们之间是多对一的关系Person.arms和逆Arm.owner。

我想编写一个简单的 NSPredicate,其中我有 NSManagedObject *arm 并且我想获取该 ARM 所属的 NSManagedObject *person到。我可以制作文本表示并查找它,但是有没有更好的方法可以通过身份查找它?也许是这样的?

NSEntityDescription *person = [NSEntityDescription entityForName:@"Person" inManagedObjectContext:MOC];
NSPredicate *personPredicate = [NSPredicate predicateWithFormat:@"%@ IN arms", arm];

干杯

尼克

最佳答案

I've got the scenario with two NSManagedObjects, Arm and Person. Between them is a many-to-one relationship Person.arms and inverse Arm.owner.

I'd like to write a simple NSPredicate where I've got the NSManagedObject *arm and I'd like to fetch the NSManagedObject *person that this arm belongs to.

那就是myArm.owner。不需要谓词;这就是逆关系的用途。

关于iphone - NSPredicate by NSManagedObject 用于多对一查找,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2571477/

相关文章:

ios - 从库中选择图像不会调用 "didFinishPickingImage"函数 - Swift

objective-c - 在 cocoa 应用程序中使用 NSTask 执行命令时 sudo 身份验证 session

macos - cocoa : Hide any window using accessibility

cocoa-touch - 在扩展中添加便利的初始值设定项并在子类上调用它们

iOS 允许在给定时间发生一次触摸事件

iphone - 如何在 iOS 7 中更改键盘的背景颜色

iphone - 自定义 UITableViewCell 内的 UISwitch 不可用

iphone - cocos2d Sprite contentSize问题

xcode - 如何在不包含 Mac OS X 10.6 SDK 的 Xcode 版本中构建它

objective-c - UITableView - 直接设置 tableHeaderView 属性与实现 -viewForHeaderInSection 方法