Last active
March 13, 2017 16:28
-
-
Save hborders/06af193c6f44788fa3bb5d84c8818cc0 to your computer and use it in GitHub Desktop.
An Objective-C pattern for making sum types - ExampleFoo
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 "ExampleFoo.h" // https://gist.github.com/hborders/094f05d932b3d7a1e389184ba525b0c3 | |
#import "ExamplePrivate.h" // https://gist.github.com/hborders/12fcbe34cf4de68c2317bad92a8e223d | |
@implementation ExampleFoo | |
- (instancetype _Nonnull)initPrivate { | |
NSLog(@"Unavailable"); | |
abort(); | |
} | |
- (instancetype _Nonnull)initWithF:(NSString * _Nonnull)f | |
g:(NSString * _Nonnull)g { | |
NSParameterAssert(f); | |
NSParameterAssert(g); | |
self = [super initPrivate]; | |
if (self) { | |
_f = f; | |
_g = g; | |
} | |
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]; | |
fooBlock(self); | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment