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 "Example.h" // https://gist.github.com/hborders/2af9b39e27b62ef9e68c65085126fe4a | |
- (void)missingReturn { | |
Example * _Nonnull fooExample = [[ExampleFoo alloc] initWithF:@"foo" | |
g:@"goo"]; | |
NSNumber * _Nonnull number = | |
[ExampleSwitcher<NSNumber *> nonnullExampleFrom:fooExample | |
switchFoo:^(ExampleFoo * _Nonnull foo_) { | |
return @(foo_.f.length + foo_.g.length); | |
} |
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 "Example.h" // https://gist.github.com/hborders/2af9b39e27b62ef9e68c65085126fe4a | |
- (void)missingAssignment { | |
Example * _Nonnull fooExample = [[ExampleFoo alloc] initWithF:@"foo" | |
g:@"goo"]; | |
NSNumber * _Nonnull __block number; | |
[fooExample switchFoo:^(ExampleFoo * _Nonnull foo_) { | |
number = @(foo_.f.length + foo_.g.length); | |
} | |
bar:^(ExampleBar * _Nonnull bar_) { |
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 "Example.h" // https://gist.github.com/hborders/e00d7ff965ca8f8df8f7e762a2269efb | |
#import "ExampleSwitcher.h" // https://gist.github.com/hborders/f378b4e0d0f1d74ff7c8149cb04c6268 | |
#import "ExampleFoo.h" // https://gist.github.com/hborders/094f05d932b3d7a1e389184ba525b0c3 | |
#import "ExampleBar.h" // https://gist.github.com/hborders/f1c231a89de11157adf46ee85880733a | |
static NSNumber * _Nonnull transformExample(Example * _Nonnull example) { | |
return [ExampleSwitcher<NSNumber *> nonnullValueFrom:example | |
switchFoo:^NSNumber * _Nonnull (ExampleFoo * _Nonnull foo_) { | |
return @(foo_.f.length + foo_.g.length); | |
} |
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 "Example.h" // https://gist.github.com/hborders/2af9b39e27b62ef9e68c65085126fe4a | |
@interface ExampleBar : Example | |
@property (nonatomic, readonly) NSInteger b; | |
@property (nonatomic, readonly) NSInteger c; | |
+ (instancetype _Nonnull)new NS_UNAVAILABLE; | |
- (instancetype _Nonnull)init NS_UNAVAILABLE; | |
- (instancetype _Nonnull)initWithB:(NSInteger)b | |
c:(NSInteger)c NS_DESIGNATED_INITIALIZER; |
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 "Example.h" // https://gist.github.com/hborders/2af9b39e27b62ef9e68c65085126fe4a | |
@interface ExampleFoo : Example | |
@property (nonatomic, readonly) NSString * _Nonnull f; | |
@property (nonatomic, readonly) NSString * _Nonnull g; | |
+ (instancetype _Nonnull)new NS_UNAVAILABLE; | |
- (instancetype _Nonnull)init NS_UNAVAILABLE; | |
- (instancetype _Nonnull)initWithF:(NSString * _Nonnull)f | |
g:(NSString * _Nonnull)g NS_DESIGNATED_INITIALIZER; |
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 { |
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 { |
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 "ExampleSwitcher.h" // https://gist.github.com/hborders/f378b4e0d0f1d74ff7c8149cb04c6268 | |
@implementation ExampleSwitcher | |
+ (NSObject * _Nonnull)nonnullValueFrom:(Example * _Nonnull)example | |
switchFoo:(NSObject * _Nonnull (^ _Nonnull)(ExampleFoo * _Nonnull foo_))fooBlock | |
bar:(NSObject * _Nonnull (^ _Nonnull)(ExampleBar * _Nonnull bar_))barBlock { | |
NSParameterAssert(example); | |
NSParameterAssert(fooBlock); | |
NSParameterAssert(barBlock); | |
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 "ExamplePrivate.h" // https://gist.github.com/hborders/12fcbe34cf4de68c2317bad92a8e223d | |
@implementation Example | |
- (instancetype _Nonnull)initPrivate { | |
return [super init]; | |
} | |
- (void)switchFoo:(void (^ _Nonnull)(ExampleFoo * _Nonnull foo_))fooBlock | |
bar:(void (^ _Nonnull)(ExampleBar * _Nonnull bar_))barBlock { | |
// Subclasses must implement and call | |
} |
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 "Example.h" // https://gist.github.com/hborders/2af9b39e27b62ef9e68c65085126fe4a | |
@interface ExampleSwitcher<ReturnType : NSObject *> : NSObject | |
+ (instancetype _Nonnull)new NS_UNAVAILABLE; | |
- (instancetype _Nonnull)init NS_UNAVAILABLE; | |
+ (ReturnType _Nonnull)nonnullValueFrom:(Example * _Nonnull)example | |
switchFoo:(ReturnType _Nonnull (^ _Nonnull)(ExampleFoo * _Nonnull foo_))fooBlock | |
bar:(ReturnType _Nonnull (^ _Nonnull)(ExampleBar * _Nonnull bar_))barBlock; | |
+ (ReturnType _Nullable)nullableValueFrom:(Example * _Nonnull)example |