Objective-C : Changing "self" value inside self
Posted
by
Oliver
on Stack Overflow
See other posts from Stack Overflow
or by Oliver
Published on 2010-12-29T00:47:18Z
Indexed on
2010/12/29
0:54 UTC
Read the original article
Hit count: 187
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 ?
© Stack Overflow or respective owner