Houman
Houman

Reputation: 66320

Description of NSManagedObject shows values, but accessing them shows NaN?

I have found here an excellent solution for creating relationships when migrating a model. I came across an odd problem within the model itself.

-(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];

...

There is an odd problem here with event.date_time I am expecting a value, but in the debugger it shows the value as (NsTimeInterval) NaN instead of the actual value.

However when I print the description of event, I can clearly see date value provided. How is this possible that it shows NaN when I do 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;

Upvotes: 2

Views: 224

Answers (1)

Houman
Houman

Reputation: 66320

I have just found it. It can be accessed as key/value pair.

Wrong:

[event date_time]

Correct:

NSDate *date_time = [event valueForKey:@"date_time"];

I was under the false impression, it would be using the properties on the model.

Upvotes: 2

Related Questions