更改自定义对象上的 NSDate?
我的应用程序有一个包含 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否在自定义对象的 NSDate-Member 上设置了属性?
要更改该值:
Have you set a property on the NSDate-Member of your custom object?
To change that value:
傻傻的我。
我需要写:
那会完美地工作。
抱歉浪费了您的时间:)
Stupid stupid me.
I needed to write:
That'll work perfectly.
Sorry for wasting your time :)