Skip to content

Instantly share code, notes, and snippets.

@hborders
Last active March 13, 2017 16:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hborders/4dd32a239e572666787793607d6c1b78 to your computer and use it in GitHub Desktop.
Save hborders/4dd32a239e572666787793607d6c1b78 to your computer and use it in GitHub Desktop.
An Objective-C pattern for making sum types - Example.m - ExampleBar
#import "ExampleBar.h" // https://gist.github.com/hborders/f1c231a89de11157adf46ee85880733a
#import "ExamplePrivate.h" // https://gist.github.com/hborders/12fcbe34cf4de68c2317bad92a8e223d
@implementation ExampleBar
- (instancetype _Nonnull)initPrivate {
NSLog(@"Unavailable");
abort();
}
- (instancetype _Nonnull)initWithB:(NSInteger)b
c:(NSInteger)c {
self = [super initPrivate];
if (self) {
_b = b;
_c = c;
}
return self;
}
- (void)switchFoo:(void (^ _Nonnull)(ExampleFoo * _Nonnull foo_))fooBlock
bar:(void (^ _Nonnull)(ExampleBar * _Nonnull bar_))barBlock {
NSParameterAssert(fooBlock);
NSParameterAssert(barBlock);
[super switchFoo:fooBlock
bar:barBlock];
barBlock(self);
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment