NSManagedObject的描述显示值,但是访问它们会显示NaN吗? [英] Description of NSManagedObject shows values, but accessing them shows NaN?

查看:94
本文介绍了NSManagedObject的描述显示值,但是访问它们会显示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];

...

event.date_time在这里有一个奇怪的问题,我期望有一个值,但是在调试器中,它将值显示为(NsTimeInterval) NaN而不是实际值.

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.

但是,当我打印事件的描述时,我可以清楚地看到所提供的日期值.当我执行event.date_time时,怎么可能显示NaN?

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;

推荐答案

我刚刚找到了它.可以作为键/值对进行访问.

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

错误:

[event date_time]

正确:

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

我有一种错误的印象,那就是使用模型上的属性.

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

这篇关于NSManagedObject的描述显示值,但是访问它们会显示NaN吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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