iOS Core数据关系故障 [英] iOS Core data relationship faults

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

问题描述

我有一个包含3个实体的核心数据模型.驱动程序,清单和作业.

I have a core data model that has 3 entities. Driver, Manifest and Jobs.

每个清单都有一个驱动程序,每个驱动程序都有多个清单,每个清单可以有一个或多个Job,每个Job都引用一个清单.

Each Manifest has one driver, each Driver has multiple Manifests, each Manifest can have one or more Jobs and each Job refers to one Manifest.

当我像这样构建对象时

//Loop through all the Manifests for the driver
for (SDZManifest *manifest in allData)
{
    //Create an new instance of manifest in core data
    Manifest *newManifest = (Manifest*)[[SKCoreDataManager sharedInstance] insertObjectforEntity:kEntity_Manifest];

    // ***
    // Set the data for this manifest
    // ***
    [newManifest setDriverID:[NSNumber numberWithInt:[manifest DriverId]]];
    [newManifest setManifestID:[manifest ManifestId]];
    [newManifest setManifestRef:[manifest ManifestRef]];
    [newManifest setSupplierID:[NSNumber numberWithInt:[manifest SupplierId]]];
    [newManifest setTruckID:[NSNumber numberWithInt:[manifest TruckId]]];

    //Get all the jobs for the manifest
    NSArray *allJobsForManifest = [manifest Jobs];
    NSMutableArray *formattedJobsForManifest = [NSMutableArray array];

    //Loop through all the Jobs for this manifiest
    for (SDZJob *job in allJobsForManifest)
    {
        //Set the returned data into a Job object
        Job *newJob = (Job*)[[SKCoreDataManager sharedInstance] insertObjectforEntity:kEntity_Job];

        [newJob setInstructions:[job Instructions]];

        [newJob setDateCreated:[job DateCreated]];

        [newJob setCreatedBy:[job CreatedBy]];

        [newJob setIsLive:[NSNumber numberWithBool:[job IsLive]]];

        [newJob setCollectionSequence:[NSNumber numberWithInt:[job CollectionSequence]]];

        [newJob setPlannedDeliveryDate:[job PlannedDeliveryDate]];
        [newJob setPlannedCollectionDate:[job PlannedCollectionDate]];

        [newJob setCustomerRef:[job CustomerRef]];
        [newJob setCustomerName:[job CustomerName]];

        // ***
        // Collection address
        // ***

        //Break down the address
        SDZAddress *collectionAddress = [job CollectionAddress];
        [newJob setCollectionAddressID:[NSNumber numberWithInt:[collectionAddress Id]]];
        [newJob setCollectionAddressLine1:[collectionAddress line1]];
        [newJob setCollectionAddressLine2:[collectionAddress line2]];
        [newJob setCollectionAddressLine3:[collectionAddress line3]];
        [newJob setCollectionAddressCity:[collectionAddress city]];
        [newJob setCollectionAddressCounty:[collectionAddress county]];
        [newJob setCollectionAddressCountry:[collectionAddress country]];
        [newJob setCollectionAddressPostcode:[collectionAddress postcode]];

        //Get the lat and lng of the collection address
        SDZGeoLocation *collectionAddressLatLng = [collectionAddress Geocode];
        [newJob setCollectionAddressLat:[collectionAddressLatLng Lat]];
        [newJob setCollectionAddressLng:[collectionAddressLatLng Lng]];

        // ***
        // Delivery address
        // ***

        //Break down the address
        SDZAddress *deliveryAddress = [job DeliveryAddress];
        [newJob setDeliveryAddressID:[NSNumber numberWithInt:[deliveryAddress Id]]];
        [newJob setDeliveryAddressLine1:[deliveryAddress line1]];
        [newJob setDeliveryAddressLine2:[deliveryAddress line2]];
        [newJob setDeliveryAddressLine3:[deliveryAddress line3]];
        [newJob setDeliveryAddressCity:[deliveryAddress city]];
        [newJob setDeliveryAddressCounty:[deliveryAddress county]];
        [newJob setDeliveryAddressCountry:[deliveryAddress country]];
        [newJob setDeliveryAddressPostcode:[deliveryAddress postcode]];

        //Get the lat and lng of the collection address
        SDZGeoLocation *deliveryAddressLatLng = [deliveryAddress Geocode];
        [newJob setDeliveryAddressLat:[deliveryAddressLatLng Lat]];
        [newJob setDeliveryAddressLng:[deliveryAddressLatLng Lng]];

        [formattedJobsForManifest addObject:newJob];

        NSLog(@"\n\n-- NEW JOB --\n%@\n\n", newJob);
    }
    //Show all Jobs for this manifest
    NSLog(@"\n\n-- JOBS FOR MANIFEST --\n%@\n\n", formattedJobsForManifest);

}

然后我将该清单对象保存到核心数据中.

I then save that Manifest object to core data.

当他们单击表格视图单元格时,我从清单清单中获取了对象并将其传递给另一个视图.当我记录传递的清单时,它会显示loggs:

When they click on the table view cell I get the object from an array of manifests and pass it to another view. When I log the passed manifest it loggs :

-- PASSED MANIFEST --
<Manifest: 0xe59d540> (entity: Manifest; id: 0xe59c3e0 <x-coredata://9F572794-745F-4E43-B4D0-9EC3506EA6E4/Manifest/p5> ; data: {
    driver = nil;
    driverID = 1;
    jobs = "<relationship fault: 0x7b3d290 'jobs'>";
    manifestID = "f705c777-9455-4792-bd84-2deada410dab";
    manifestRef = 001;
    supplierID = 2;
    truckID = 8;
})

当我登录NSLog(@"\n\n-- PASSED MANIFEST JOBS --\n%@\n\n", [passedManifest jobs]);时,结果是

-- PASSED MANIFEST JOBS --
Relationship 'jobs' fault on managed object (0xe59d540) <Manifest: 0xe59d540> (entity: Manifest; id: 0xe59c3e0 <x-coredata://9F572794-745F-4E43-B4D0-9EC3506EA6E4/Manifest/p5> ; data: {
    driver = nil;
    driverID = 1;
    jobs = "<relationship fault: 0x7b3d290 'jobs'>";
    manifestID = "f705c777-9455-4792-bd84-2deada410dab";
    manifestRef = 001;
    supplierID = 2;
    truckID = 8;
})

为什么要说受管理对象(0xe59d540)上的作业"错误?

当我NSLog(@"\n\n-- JOB COUNT --\n%u\n\n", [[passedManifest jobs] count]);时,它返回 0

推荐答案

核心数据故障仅表示尚未从磁盘"中加载数据.

A core data fault simply means that the data has not been loaded from the "disk" yet.

但是,它将在需要时自动为您加载,因此无需担心.

It will be automatically loaded for you however, when needed, so there is nothing to be concerned about.

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

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