de.*_*de. 5 core-data objective-c nspredicate
我有一个NSManagedObject相关的对象.该关系由keyPath描述.
现在我想在表格视图中显示这些相关对象.当然,我可以将NSSet这些对象作为数据源,但我更愿意重新获取对象,NSFetchedResultsController以便从其功能中受益.
如何创建描述这些对象的谓词?
Mar*_*n R 13
要使用获取的结果控制器显示给定对象的相关对象,可以在谓词中使用反向关系.例如:

要显示与给定父级相关的子级,请使用带有以下提取请求的已提取结果控制器:
Parent *theParent = ...;
NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"Child"];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"parent = %@", theParent];
[request setPredicate:predicate];
Run Code Online (Sandbox Code Playgroud)
对于嵌套关系,只需按反转顺序使用反向关系.例:

要显示给定国家/地区的街道:
Country *theCountry = ...;
NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"Street"];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"city.country = %@", theCountry];
[request setPredicate:predicate];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3883 次 |
| 最近记录: |