Changing NSDate on custom object?
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 dateByAddingTimeInte开发者_Python百科rval: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.
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);
Stupid stupid me. I needed to write:
self.nextSendAttempt = cal;
That'll work perfectly.
Sorry for wasting your time :)
精彩评论