CoreData 关系故障? [英] CoreData relationship fault?

查看:19
本文介绍了CoreData 关系故障?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个与单位有对多"关系的订单.当我尝试按顺序记录单位 (NSSet) 时,出现错误错误:

I have an Order which has a "to-many" relationship with Units. When I try to log the units (NSSet) in Order, I get a fault error:

NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Order" 
                                          inManagedObjectContext:mainContext];
[fetchRequest setEntity:entity];
NSArray *fetchedObjects = [mainContext executeFetchRequest:fetchRequest 
                                                     error:nil];
for (Order *order in fetchedObjects) {

    NSLog(@"%@", [order units]);
    break;
}        
[fetchRequest release];

结果:

Relationship 'units' fault on managed object (0x6d9dd00) <Order: 0x6d9dd00> (entity: Order; id: 0x6d88e40 <x-coredata://97A3F3D5-ABA7-499A-A460-5E25CF49C528/Order/p1> ; data: {
    composition = Hemlock;
    condition = "";
    consignee = "";
    consigneeCompanyName = "";
    contactAlternatePhone = "";
    contactEmail = "";
    contactFirstName = "";
    contactLastName = "";
    contactPhone = "";
    customer = "Havard Empire";
    customerCompanyName = "";
    customerNotes = "";
    dateDue = "1/13/2012 12:00:00 AM";
    dateEntered = "1/6/2012 12:00:00 AM";
    dateOrdered = "1/6/2012 12:00:00 AM";
    deliveryAddress1 = "";
    deliveryAddress2 = "";
    deliveryCity = "";
    deliverySpecialInstructions = "";
    deliveryState = "";
    deliveryZip = "";
    depth = 01;
    detail = "";
    freightRate = "";
    grade = Cull;
    instructionsDirectionsNotes = "";
    lastUpdated = "1/6/2012 3:00:43 PM";
    length = 01;
    location = "Lucedale, ms";
    matsPerLoad = "";
    memoLineNotes = "";
    notes = "";
    orderID = 201205134922479;
    orderNumber = 01062012;
    pUP = Cable;
    pricePerItem = "";
    purchaseOrderNumber = "";
    pushToQuickBooks = True;
    quantity = 0;
    quickbooksCompany = 1;
    salesman = "Accounting Adj";
    separateRate = False;
    taxRate = "";
    totalLoads = "";
    type = "2ply Mat";
    units = "<relationship fault: 0x6dacf20 'units'>";
    vendorID = 10;
    width = 01;
})

不打印单位.它说 "";

另外,当我只需要单位时,为什么要打印整个对象?

Also, why is it printing the entire object when I only want units?

推荐答案

这不是错误 - 它是 Core Data 的一个特性,称为故障".这是 Apple 的说明:

This isn't an error - it is a feature of Core Data called 'faulting'. Here is Apple's description:

故障会减少您的应用程序消耗的内存量.一个故障是一个占位符对象,代表一个托管对象尚未完全实现,或一个集合对象代表关系:

Faulting reduces the amount of memory your application consumes. A fault is a placeholder object that represents a managed object that has not yet been fully realized, or a collection object that represents a relationship:

托管对象错误是适当类的实例,但是它的持久变量尚未初始化.关系错误是代表集合类的子类关系.故障允许核心数据在对象图.由于未实现故障,管理对象故障消耗更少的内存,并且与故障相关的托管对象不会完全需要在内存中表示.

A managed object fault is an instance of the appropriate class, but its persistent variables are not yet initialized. A relationship fault is a subclass of the collection class that represents the relationship. Faulting allows Core Data to put boundaries on the object graph. Because a fault is not realized, a managed object fault consumes less memory, and managed objects related to a fault are not required to be represented in memory at all.

如果您想查看每个 Unit 对象,则必须专门访问它们.请尝试以下操作:

If you want to see each Unit object then you will have to specifically access them. Try the following:

for (Order *order in fetchedObjects) {
    for (Unit *unit in [order units]) {
       NSLog(@"%@", unit);
       //I am not at a computer, so I cannot test, but this should work. You might have to access each property of the unit object to fire the fault, but I don't believe that is necessary.
    }
}     

这篇关于CoreData 关系故障?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆