Created
September 7, 2011 06:52
-
-
Save taketin/1199929 to your computer and use it in GitHub Desktop.
Objective-C Protocol Template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* MyDelegateClass.h | |
*/ | |
#import <Foundation/Foundation.h> | |
@protocol MyDelegate; | |
@interface MyDelegateClass : NSObject { | |
id <MyDelegate>_delegate; | |
} | |
@property (nonatomic, assign) id <MyDelegate>_delegate; | |
- (void)someMethod; | |
@end | |
@protocol MyDelegate <NSObject> | |
@optional | |
- (void)doSomething; | |
@end | |
/** | |
* MyDelegateClass.m | |
*/ | |
#import "MyDelegateClass.h" | |
@implementation MyDelegateClass | |
@synthesize _delegate; | |
- (void)someMethod { | |
// Call DelegateMethod | |
if ([_delegate respondsToSelector:@selector(doSomething)]) { | |
[_delegate performSelector:@selector(doSomething)]; | |
} | |
} | |
@end | |
/** | |
* ClientViewController.h | |
*/ | |
#import "MyDelegateClass.h" | |
@interface ClientViewController : UIViewController <MyDelegate> { | |
} | |
@end | |
/** | |
* ClientViewController.m | |
*/ | |
#import "ClientViewController.h" | |
@implementation AccountsViewController | |
#pragma mark - MyDelegate DelegateMethods | |
- (void)doSomething { | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment