Skip to content

Instantly share code, notes, and snippets.

@konrad1977
Created June 24, 2014 09:32
Show Gist options
  • Save konrad1977/93da1aa745d1f17dc5f4 to your computer and use it in GitHub Desktop.
Save konrad1977/93da1aa745d1f17dc5f4 to your computer and use it in GitHub Desktop.
Simple example of using Builder pattern in Objective-C
//header file
typedef void (^ColorThemeBuilder)(id<ColorThemeProtocol> colorTheme);
@interface ThemeBuilder : NSObject <ColorThemeProtocol>
- (instancetype)initColorTheme:(ColorThemeBuilder)builder;
@end
//Implementation
@implementation ThemeBuilder
@synthesize backgroundColor;
@synthesize textColor;
@synthesize hudTextColor;
@synthesize hudBackgroundColor;
@synthesize tintColor;
@synthesize title;
@synthesize details;
- (instancetype)initColorTheme:(ColorThemeBuilder)builder {
self = [super init];
if (self) {
builder(self);
}
return self;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment