Skip to content

Instantly share code, notes, and snippets.

@taketin
Created September 7, 2011 06:52
Show Gist options
  • Save taketin/1199929 to your computer and use it in GitHub Desktop.
Save taketin/1199929 to your computer and use it in GitHub Desktop.
Objective-C Protocol Template
/**
* 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