更改自定义对象上的 NSDate?

发布于 2024-12-02 22:05:43 字数 724 浏览 5 评论 0原文

我的应用程序有一个包含 NSDate 的自定义对象。 我想在我的应用程序中更改此 NSDate,但这不可能吗?

代码:

所以这是我的对象中的一个方法,应该根据另一个变量(sentcount)来更改日期:

(void)increaseSentAttempts
{
sentCount++;

NSDate *cal = [NSDate date];

if (sentCount < 3) {
    //add 1 minute
    cal = [cal dateByAddingTimeInterval:60];
}
else if(sentCount < 10)
{
    //add 5 minutes
    cal = [cal dateByAddingTimeInterval:300];
}
else if(sentCount < 23)
{
    //add 1 hour
    cal = [cal dateByAddingTimeInterval:3600];
}
else {
    //add 15 hours
    cal = [cal dateByAddingTimeInterval:54000];
}


//sæt nextsent attribut
nextSendAttempt = cal;

}

nextSendAttempt 是自定义对象中的我的 NSDate。但是当应用程序崩溃时,nextsendattempt = cal;不可能的。

My app has a custom object that contains an NSDate.
I want to change this NSDate in my app, but this is not possible?

Code:

So this is a method from my object, that is supposed to alter the date, depending on another variable (sentcount):

(void)increaseSentAttempts
{
sentCount++;

NSDate *cal = [NSDate date];

if (sentCount < 3) {
    //add 1 minute
    cal = [cal dateByAddingTimeInterval:60];
}
else if(sentCount < 10)
{
    //add 5 minutes
    cal = [cal dateByAddingTimeInterval:300];
}
else if(sentCount < 23)
{
    //add 1 hour
    cal = [cal dateByAddingTimeInterval:3600];
}
else {
    //add 15 hours
    cal = [cal dateByAddingTimeInterval:54000];
}


//sæt nextsent attribut
nextSendAttempt = cal;

}

nextSendAttempt is my NSDate in the custom object. But seeing as the app crashes, the nextsendattempt = cal; isnt possible.

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

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

发布评论

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

评论(2

别把无礼当个性 2024-12-09 22:05:43

您是否在自定义对象的 NSDate-Member 上设置了属性?

@interface MyClass : NSObject
{
    NSDate *myDate;
}
@property (retain) NSDate *myDate;
@end;

要更改该值:

MyClass *obj = ...;
NSDate *newDate = ...;
NSLog(@"oldDate: %@",obj.myDate);
obj.myDate = newDate;
NSLog(@"newDate: %@",obj.myDate);

Have you set a property on the NSDate-Member of your custom object?

@interface MyClass : NSObject
{
    NSDate *myDate;
}
@property (retain) NSDate *myDate;
@end;

To change that value:

MyClass *obj = ...;
NSDate *newDate = ...;
NSLog(@"oldDate: %@",obj.myDate);
obj.myDate = newDate;
NSLog(@"newDate: %@",obj.myDate);
庆幸我还是我 2024-12-09 22:05:43

傻傻的我。
我需要写:

self.nextSendAttempt = cal;

那会完美地工作。

抱歉浪费了您的时间:)

Stupid stupid me.
I needed to write:

self.nextSendAttempt = cal;

That'll work perfectly.

Sorry for wasting your time :)

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