Objective-C : Changing "self" value inside self
- by Oliver
Hello,
I have a category on NSDate, and I want to implement some functions to manipulate the date, like :
NSDate *thedate = [NSDate date];
[thedate setToMidnight];
so I have a function in NSDate like :
-(void)setToMidnight {
some code with calendars and comps
self = theNewDate;
}
This works inside the function, but outside this member function, thedate has not changed.
I understand this malfunction because I've been told that self is just a local variable created inside the member function.
So, how can I make this work ?
Of course, I could have written :
thedate = [thedate dateAsMidnightDate]
or thedate = [NSDate dateAtMidnightFromDate:thedate]
but I feel it has more sense inside the instance class, as I don't want to change the date but just adjust some values of the previously created one.
Can you help me to achieve this ?