Objective-C element variable assignment?

I have an objective-c class with member variables. I create getters and setters for each of them. Mostly for educational purposes. My setter looks like this:

- (void) setSomething:(NSString *)input {
 something = input;
}

However, in C ++ and other languages ​​I've worked with in the past, you can reference a member variable using a pointer this, for example this->something = input. In objective-c, this is called self. So I was wondering if something like this is possible in objective-c? Something like that:

- (void) setSomething:(NSString *)input {
 [self something] = input;
}

But this will cause getter for something. Therefore, I am not sure. So my question is:

Is there a way that I can perform an assignment using a self pointer?

If so, how?

Is it good practice or is it evil?

Thank!

+3
2

, , ++, self this:

self->something = input;
+4

"" , ...

something = input;

... "-". (.. "", .)

, , , , , (, , NSString).

, ( Objective-C / - ), - :

- (void) setSomething:(NSString *)input {
    if(something != input) {
        [input retain];
        [something release];
        something = input;
    }
}
+2

Source: https://habr.com/ru/post/1782361/


All Articles