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.
- , , , ( parent) - , , , , .
:
wheel.carDelegate = self;
[carDelegate moveForward];
, , !
, - (, , , , - , ).
... , ActionScript "" .
: . parent Objective-C - .
parent
Objective-C , , "" . superclass, parent. , "".
superclass
"", , , . , . , , parent . , , , , Objective-C car "". , XML-, . , "" . , Objective-C, "" .
car
"" "": . "" . , , "" , node "" .
: - , . , , .
Objective-C, (, Cocoa), -. , , , , . , initWithParent: initWithCar: .
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
,
:)
- , . , , . self super , .
- , .
, , . Cocoa , , , , :
. , . , , ( ). Cocoa.
. Key-Value Observing. A ( ) B ().
Key-Value Observation, KVO. .