最初のオブジェクト 'Controller'があり、参照用に 'self'を渡しながら 'Tasks'という別のオブジェクトを初期化します。 Tasksオブジェクトは、通信して、スーパー 'Controller'オブジェクトにメッセージを送信できるようになりました。これはオブジェクト間の通信に適していますか?これは通常どのように行われていますか?私はちょうどプログラミングについて本当に学ぶようになったので、これは大丈夫ですか?この時点まで、私は代理人と通知に頼ってきました。これはいい練習ですか?オブジェクト間の通信 - 別のオブジェクトへの自己継承/ Objective-C、Cocoa
例:
// Controller Object
task = [[Task alloc] initWithController: self];
- (void) runMethod: (NSString *) incoming {
NSLog(@"%@", incoming);
}
// Task Object
- (id) initWithController: (Controller *) ctrlr {
controllerPointer = ctrlr;
[controllerPointer runMethod:@"hello"];
return self
}
// All this should print out "hello"
とオブジェクトとの間の相互作用、通信の任意の他の方法がありますか?