0

我有一个名为 CaseHistory 的父实体,它可以有多个 MedicationCase 实体实例。

代码如下:

@interface CaseHistory : NSManagedObject
@property (nonatomic, retain) NSSet *medicationCaseSet;
@end

@interface MedicationCase : NSManagedObject

@property (retain, nonatomic)CaseHistory *caseHistory;
@end

然后,我新建一个 MedicationCase 实例,并将其插入到上下文中,然后保存。

_tempMedicationCase =  [[BusinessManager sharedInstance].caseHistoryManager newMedicationCase];
 [[BusinessManager sharedInstance].caseHistoryManager insertnewMedicationCase:_tempMedicationCase];

 if(! [_tempCaseHistory.medicationCaseSet containsObject:_tempMedicationCase])
  {
     [_tempCaseHistory addMedicationCaseSetObject:_tempMedicationCase];
  }
[[BusinessManager sharedInstance] save];

然后我获取结果,没关系,但是当我退出应用程序,然后获取旧结果时,它变为 NULL。

(lldb) po caseHistoryArray
<__NSArrayM 0x20002a80>(
<CaseHistory: 0x200017e0> (entity: CaseHistory; id: 0x20002380 <x-coredata://ADB63B4E-7622-4101-9546-CFA53ACD28E9/CaseHistory/p1> ; data: {
    medicationCaseSet =     (
    );
})
)

内容文件是:

 <model name="" userDefinedModelVersionIdentifier="" type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="2061" systemVersion="12E55" minimumToolsVersion="Xcode 4.3" macOSVersion="Automatic" iOSVersion="Automatic">
    <entity name="CaseHistory" syncable="YES">
        <relationship name="medicationCaseSet" optional="YES" toMany="YES" deletionRule="Nullify" destinationEntity="MedicationCase" inverseName="caseHistory" inverseEntity="MedicationCase" syncable="YES"/>
    </entity>
    <entity name="MedicationCase" syncable="YES">
        <relationship name="caseHistory" optional="YES" minCount="1" maxCount="1" deletionRule="Nullify" destinationEntity="CaseHistory" inverseName="medicationCaseSet" inverseEntity="CaseHistory" syncable="YES"/>
    </entity>
</model>
4

0 回答 0