536Adding a custom delegate
MyClassWithDelegate.h
#import <Cocoa/Cocoa.h> @protocol MyClassWithDelegaet <NSObject> @optional - (void)myDelegateMethod:(NSString*)tsst; @end @interface MyClassWithDelegate : NSView { id <MyClassWithDelegate> delegate; } @property (nonatomic, assign) id <MyClassWithDelegate> delegate; @end
MyClassWithDelegate.m
#import "MyClassWithDelegate.h" @implementation MainView @synthesize delegate; - (void)anyEvent:(NSEvent *)e { // an event or something like that // send delegate [[self delegate] myDelegateMethod:@"sss"]; } @end
Thanks to Jon Sterling for his digest of Apple’s ‘How Delegation Works‘