coredata NSFetchRequest一对多关系托管对象上的关系错误

时间:2014-12-30 16:48:20

标签: ios objective-c iphone core-data

我有一个包含以下实体的coredata项目:

我试图获取该类别的内容基础列表:

这是我的coredata clasess .h:

@interface Content : NSManagedObject

@property (nonatomic, retain) NSString * contenido;
@property (nonatomic, retain) NSNumber * index;
@property (nonatomic, retain) NSString * titulo;
@property (nonatomic, retain) NSNumber * uploadCloudKit;
@property (nonatomic, retain) Categories *category;

---

@class Content;

@interface Categories : NSManagedObject

@property (nonatomic, retain) NSString * categoryName;
@property (nonatomic, retain) NSSet *content;
@end



NSEntityDescription *categoryDescription = [ NSEntityDescription entityForName:@"Categories" inManagedObjectContext:moc];

NSFetchRequest *categoRequest = [NSFetchRequest new];
categoRequest.entity = categoryDescription;
NSPredicate *categoPredicate = [NSPredicate predicateWithFormat:@"categoryName like %@", category];
categoRequest.predicate = categoPredicate;
 NSArray *results = [moc executeFetchRequest:categoRequest error:&error];

但是当我尝试访问我得到的类别的结果上的内容时:

po [results valueForKey:@"content"]
<__NSArrayI 0x6080000243a0>(
Relationship 'content' fault on managed object (0x6080000a2220) <Categories: 0x6080000a2220> (entity: Categories; id: 0x40002b <x-coredata://FDBA3FB2-F1F8-498E-9071-3A5D1ABE66F0/Categories/p1> ; data: {
    categoryName = movies;
    content = "<relationship fault: 0x610000030fa0 'content'>";
})
)

你们中的任何人都知道如何获得结果的内容项目?

我真的很感谢你的帮助

1 个答案:

答案 0 :(得分:2)

这是CoreData的正常行为。你应该阅读Apple Documentation。在那里,您可以阅读CoreData的故障对象。用两个词来说 - fault意味着CoreData有这个对象但是知道(出于某种原因,CoreData不会打印出对象的所有字段)。 为了看到所有的领域,你应该这样做:

[categoRequest setReturnsObjectsAsFaults:NO];

但是我建议你只为调试做这件事,因为CoreData更聪明并且知道如何处理内存管理)