Skip to content

Instantly share code, notes, and snippets.

@peerasak-u
Created August 23, 2013 05:32
Show Gist options
  • Select an option

  • Save peerasak-u/6315840 to your computer and use it in GitHub Desktop.

Select an option

Save peerasak-u/6315840 to your computer and use it in GitHub Desktop.
เวลาจะใช้ก็แค่เรียก [[DelegateHelper sharedInstance].delegate delegateHelperSomething]; จบข่าว
#import <Foundation/Foundation.h>
@class DelegateHelper;
@protocol DelegateHelperDelegate <NSObject>
- (void) delegateHelperSomething;
@end
@interface DelegateHelper : NSObject
@property (weak, nonatomic) id <DelegateHelperDelegate> delegate;
+ (DelegateHelper*)sharedInstance;
@end
#import "DelegateHelper.h"
@implementation DelegateHelper
+ (DelegateHelper*)sharedInstance
{
static dispatch_once_t pred = 0;
__strong static id _sharedObject = nil;
dispatch_once(&pred, ^{
NSLog(@"DataService: dispatch op");
_sharedObject = [[self alloc] init]; // or some other init method
});
return _sharedObject;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment