与 NSDates 不工作、不兼容的指针类型相比

发布于 2024-09-24 09:34:43 字数 599 浏览 0 评论 0原文

嘿,我正在尝试将用户打开应用程序的日期与当前的日期进行比较。 (基本上,他们使用该应用程序的时间是多少天)

这是代码:

- (NSInteger) daysAfterDate: (NSDate *) aDate
{
    NSTimeInterval ti = [self timeIntervalSinceDate:aDate]; //#1
    return (NSInteger) (ti / D_DAY); //#2
}  //#3

-(void)load {

        NSDate *birthdate = [prefs objectForKey:@"Birthdate"];

    rock_Age =  daysAfterDate(birthdate);

}

错误:

1.)它告诉我初始化中的类型不兼容 2.) D_DAY Undecared

警告:

3.) 控制到达非 void 函数的末尾

如果我完全错误地执行了此操作,(因为我一生都无法理解 NSDate 类:/)我很乐意采取替代方法来执行此操作: )

感谢所有帮助, 谢谢 ——杰克逊·史密斯

Hey i am trying to compare the date on which the user opens the app to the date it is currently. (basically, how long they've had the app in days)

Here is the code:

- (NSInteger) daysAfterDate: (NSDate *) aDate
{
    NSTimeInterval ti = [self timeIntervalSinceDate:aDate]; //#1
    return (NSInteger) (ti / D_DAY); //#2
}  //#3

-(void)load {

        NSDate *birthdate = [prefs objectForKey:@"Birthdate"];

    rock_Age =  daysAfterDate(birthdate);

}

errors:

1.) it tells me incompatible types in initialization
2.) D_DAY Undecared

warning:

3.) control reaches end of non void function

If i did this completely wrong, (because for the life of me i cannot understand the NSDate class :/) I would gladly take an alternative to doing this :)

all help is appreciated,
Thank you
-Jackson Smith

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

坦然微笑 2024-10-01 09:34:43

加载方法是正确的,以下内容应该适用于 -[daysAfterDate:]

#define D_DAY        86400

-(NSInteger)daysAfterDate:(NSDate *)aDate {
    NSTimeInterval ti = [[NSDate date] timeIntervalSinceDate:aDate];
    return (NSInteger) (ti / D_DAY);
}

1) 是因为 self 可能不是 NSDate。使用 [NSDate date] 获取当前时间/日期。
2) 是因为你必须定义 D_DAY
3)仅因2)而发生。

我希望这有帮助。

以下文章也可能提供信息:(Ars Technica)

The load method is correct, the following should work for -[daysAfterDate:].

#define D_DAY        86400

-(NSInteger)daysAfterDate:(NSDate *)aDate {
    NSTimeInterval ti = [[NSDate date] timeIntervalSinceDate:aDate];
    return (NSInteger) (ti / D_DAY);
}

1) is because self is probably no NSDate. Use [NSDate date] to get the current time/date.
2) is because you have to define D_DAY
3) only happens because of 2).

I hope this helps.

The following article might also be informative: (Ars Technica)

↘人皮目录ツ 2024-10-01 09:34:43

本地方法 timeIntervalSinceData 是否返回“NSTimeInterval”(typdef double)?我猜它不会,因此会出现错误 - 但代码不在这里可见。

我们需要查看更多代码来帮助您 - 但未声明的 D_DAY 应该很容易解决。假设它不是标头中某处的 #define,您需要在该函数或文件的更高层中指定它的内容。我猜你只是在某个地方缺少一个 #define 来输入特定值 - 至少通过语法。

警告是因为这个错误 - 解析器不知道如何很好地完成事情,直到你解决了这个问题。

Does the local method timeIntervalSinceData return an "NSTimeInterval" (typdef double)? I'm guessing it doesn't, hence the error - but the code isn't here to see.

We need to see a bit more code to help you - but the D_DAY undeclared should be easy to resolve. Assuming it's not a #define somewhere in your headers, you need to specify what it is in that function or higher up in the file. I'm guessing you're just missing a #define somewhere that puts in a specific value - at least by syntax.

The warning is because of this error - the parser doesn't know how to complete things nicely until you've fixed that.

策马西风 2024-10-01 09:34:43

1)我认为它谈论的是“自我”;这是一次约会?

for 1) i think it talks about "self" ;it is a date?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文