Last active
March 13, 2017 16:43
-
-
Save hborders/4dd32a239e572666787793607d6c1b78 to your computer and use it in GitHub Desktop.
An Objective-C pattern for making sum types - Example.m - ExampleBar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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