Is a `super` local variable?

// A : Parent
@implementation A
-(id) init
{
    // change self here then return it
}
@end A

A *a = [[A alloc] init];

and. Just wondering if the local variable itself or the global one? If it is local, then what is the point self = [super init]in init? I can successfully determine some local variable and use it like this: why should I assign it self.

-(id) init
{
    id tmp = [super init];
    if(tmp != nil) {
        //do stuff
    }
    return tmp;
}

b. If it [super init]returns some other instance of the object, and I have to overwrite self, then I can no longer access the methods of A, since this will be a completely new object? I'm right?

with. superand self, pointing to the same memory, and the main difference between them is the search order of the method. I'm right?

Sorry, I don’t have a Mac to try, studying theory at the moment ...

+3
source share
2

Dreamlax ... , .

. , - ? , = [ init] init? , .

self . . , . - _cmd, .

self, , self . , self = [super init], init - , .

. [super init] , , A , ? ?

super init -, A, - . , Objective-C . , , , super init, A, A. A, , , A .

; , Objective-C . , . , , . , , .

. , - . ?

. super . super . , super , , objc_msgSendSuper(), - - "" , , .

+5
  • - , . Objective-C , . self _cmd. _cmd - , .

  • super , , , .

  • super - , . , .

+2

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


All Articles