Last active
March 13, 2017 16:42
-
-
Save hborders/2af9b39e27b62ef9e68c65085126fe4a to your computer and use it in GitHub Desktop.
An Objective-C pattern for making sum types - Example.h
This file contains hidden or 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 <Foundation/Foundation.h> | |
@class ExampleFoo; | |
@class ExampleBar; | |
@interface Example : NSObject | |
// notice there is no public designated initializer, so consumers can't instantiate Example directly. | |
// They must instantiate a subclass. | |
+ (instancetype _Nonnull)new NS_UNAVAILABLE; | |
- (instancetype _Nonnull)init NS_UNAVAILABLE; | |
// Consumers will use this method to unpack the sum type | |
- (void)switchFoo:(void (^ _Nonnull)(ExampleFoo * _Nonnull foo_))fooBlock | |
bar:(void (^ _Nonnull)(ExampleBar * _Nonnull bar_))barBlock NS_REQUIRES_SUPER; | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment