What is the right term for a parent?

In Actioncipt, Parent means an object that contains an instance. So if a car has a wheel, the wheel can tell the car to move forward with

parent.moveForward

However, in Obj-C, the parent refers to the superclass (not sure why they have super and the parent means the same thing).

I can’t find the equivalent of the parent style of the Action script, but then I really don’t know what to even look for. Is there an easy way to do this in Obj-C, or do I need to manually pass the link to the instance when I create it? I tried this and it threw an error, but since I am new to Obj-C, I just wanted to make sure that I worked correctly.

+5
source share
6 answers

- , , , ( parent) - , , , , .

:

wheel.carDelegate = self;

:

[carDelegate moveForward];

, , !

, - (, , , , - , ).

+4

... , ActionScript "" .

: . parent Objective-C - .

Objective-C , , "" . superclass, parent. , "".

"", , , . , . , , parent . , , , , Objective-C car "". , XML-, . , "" . , Objective-C, "" .

"" "": . "" . , , "" , node "" .

: - , . , , .

+6

Objective-C, (, Cocoa), -. , , , , . , initWithParent: initWithCar: .

@interface Car : Object
{
    Wheel[4] wheels;
}

- (void) goFoward:(Wheel *) wheel;

@end

@interface Wheel : Object
{
    Car *parent;
    float tirePressure;
    // etc . . .
}

- initWithCar:(Car *) aCar;

@end

@implementation Car
- init
{
    self = [super init];
    if (!self) return nil;

    unsigned i;
    for (i = 0; i < 4; i++)
        wheels[i] = [[Wheel alloc] initWithCar:self];

    return self;
}

- (void) goForward:
@end

@implementation Wheel
- initWithCar: (Car *) aCar
{
    self = [super init];
    if (!self) return nil;

    parent = aCar;

    return self;
}
@end
+3

,

:)

  • - , . , , . self super , .

  • - , .

+2

, , . Cocoa , , , , :

+1

Key-Value Observation, KVO. .

+1

All Articles