我应该从苹果的Core Data Utility教程中获得什么值? [英] What values am I supposed to be getting from Apple's Core Data Utility tutorial?

查看:112
本文介绍了我应该从苹果的Core Data Utility教程中获得什么值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在关注 Core Data Utility教程,我已实现自定义管理对象类。它构建和运行良好,但值似乎不正确。我的CDCLI.cdcli文件中有这样的对象:

I'm following the Core Data Utility tutorial and I've implemented the custom managed object class. It builds and runs fine but the values don't seem to be correct. My CDCLI.cdcli file is full of objects like this one:

<object type="RUN" id="z114">
    <attribute name="processid" type="int64">1334</attribute>
    <attribute name="date" type="date">369155986.60885798931121826172</attribute>
</object>

date属性看起来不像日期。日期和processID属性设置如下:

That "date" attribute doesn't look like a date. The date and the processID attribute are being set like so:

// Attribute: Date
NSAttributeDescription *dateAttribute = [[NSAttributeDescription alloc] init];

[dateAttribute setName:@"date"];
[dateAttribute setAttributeType:NSDateAttributeType];
[dateAttribute setOptional:NO];

// Attribute: Process ID
NSAttributeDescription *idAttribute = [[NSAttributeDescription alloc] init];

[idAttribute setName:@"processID"];
[idAttribute setAttributeType:NSInteger64AttributeType];
[idAttribute setOptional:NO];
[idAttribute setDefaultValue:[NSNumber numberWithInteger:-1]];

基于以下方法,我期望接收0作为processID属性值我不是。

Based on the following method, I was expecting to receive "0" as the processID attribute value, which I'm not.

- (void)setNilValueForKey:(NSString *)key {

    if ([key isEqualToString:@"processID"]) {
        self.processID = 0;
    } else {
        [super setNilValueForKey:key];
    }
}

其实,添加一些NSLog语句

In fact, adding a few NSLog statements to that method tells me it isn't even being called, which I'll have to figure out.

有人知道什么日期和processID属性是假设

Does anyone know what the date and processID attributes are supposed to look like so I can be sure I'm getting the correct values?

推荐答案

日期值看起来不错。内部格式是自参考日期(2001年1月1日,GMT)以来的秒数。该值约为11.7年,这似乎是一个合理的日期。

The date value looks good to me. The internal format is the number of seconds since the reference date (Jan 1, 2001, GMT). That value would be approximately 11.7 years, which seems like a reasonable date.

同样,1334的进程ID似乎是一个适当的PID值。

Likewise, the process ID of 1334 seems to be an appropriate value for a PID.

最后,在代码中,您可以这样做:

Finally, in your code, you do this:

if ([key isEqualToString:@"ProcessID"]) {

但如果属性名称不一致,日志显示 processid ,您的第一组代码使用 processID ,第二组代码使用 ProcessID

but your usage if the attribute name seems inconsistent. The log shows processid, your first set of code uses processID, and the second set of code uses ProcessID.

这篇关于我应该从苹果的Core Data Utility教程中获得什么值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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