Objective-C member variable assignment?
Posted
by
Alex
on Stack Overflow
See other posts from Stack Overflow
or by Alex
Published on 2010-12-27T21:44:52Z
Indexed on
2010/12/27
21:53 UTC
Read the original article
Hit count: 348
objective-c
|getters-setters
I have an objective-c class with member variables. I am creating getters and setters for each one. Mostly for learning purposes. My setter looks like the following:
- (void) setSomething:(NSString *)input {
something = input;
}
However, in C++ and other languages I have worked with in the past, you can reference the member variable by using the this
pointer like this->something = input
. In objective-c this is known as self
. So I was wondering if something like that is possible in objective-c? Something like this:
- (void) setSomething:(NSString *)input {
[self something] = input;
}
But that would call the getter for something
. So I'm not sure. So my question is:
Is there a way I can do assignment utilizing the self pointer?
If so, how?
Is this good practice or is it evil?
Thanks!
© Stack Overflow or respective owner