Instantly share code, notes, and snippets.

Embed
What would you like to do?
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