我在这里找到excellent solution用于在迁移模型时创建关系。我在模型中遇到了一个奇怪的问题。
-(BOOL)createRelationshipsForDestinationInstance:(NSManagedObject *)dInstance entityMapping:(NSEntityMapping *)mapping manager:(NSMigrationManager *)manager error:(NSError *__autoreleasing *)error
{
NSError *superError = nil;
BOOL ismappingSuccess = [super createRelationshipsForDestinationInstance:dInstance entityMapping:mapping manager:manager error:&superError];
if (ismappingSuccess && [dInstance.entity.name isEqualToString:@"FTEvent"]){
FTEvent *event = (FTEvent*)dInstance;
NSDate *date = [NSDate dateWithTimeIntervalSinceReferenceDate:event.date_time];
...
event.date_time
这里有一个奇怪的问题我期待一个值,但在调试器中它将值显示为(NsTimeInterval) NaN
而不是实际值。
但是,当我打印事件描述时,我可以清楚地看到提供的日期值。当我NaN
时,它如何显示event.date_time
?
Printing description of event:
<NSManagedObject: 0xbbb9b80> (entity: FTEvent; id: 0xbbbab90 <x-coredata://069BC324-2002-4DBA-879A-DC085C645903/FTEvent/p1> ; data: {
"date_time" = "2014-04-10 23:00:00 +0000";
"is_deleted" = 0;
key = "4F6646FF-4110-427F-B2FD-3CFCAF777793";
notes = Fdsfdsfd;
rating = 1;
record = nil;
timestamp = "2045-04-11 01:19:06 +0000";
})
FTEvent:
@class FTRecord;
@interface FTEvent : NSManagedObject
{
BOOL is_edited;
}
@property (nonatomic) NSTimeInterval date_time;
@property (nonatomic) BOOL is_deleted;
@property (nonatomic, retain) NSString * key;
@property (nonatomic, retain) NSString * notes;
@property (nonatomic) int16_t rating;
@property (nonatomic) NSTimeInterval timestamp;
@property (nonatomic, retain) FTRecord *record;
答案 0 :(得分:2)
我刚刚找到它。它可以作为键/值对访问。
<强>错误:强>
[event date_time]
<强>正确:强>
NSDate *date_time = [event valueForKey:@"date_time"];
我受到了错误的印象,它将使用模型上的属性。