Created
September 18, 2020 15:07
-
-
Save mlavergn/61cdd70b799987e482bba84a69751935 to your computer and use it in GitHub Desktop.
Objective-C static block members
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
/* | |
* Objective-C static block members compatible with Swift closure syntax | |
* Two examples, A: with a return value and B: with parameters, can be combined | |
* Objective-C lacks associated types and tuples, thus NSArray* for return type | |
* Note that class specifiers do NOT synthesize getters / setters | |
*/ | |
/// .h | |
@interface Foo | |
/// A: block with return value | |
@property (class, copy) NSArray *(^ mockResultTypeA)(void); | |
/// B: block with params | |
@property (class, copy) void(^ mockResultTypeB)(NSString *, NSError *); | |
@end | |
/// .m | |
static NSArray *(^ _mockResultTypeA)(void); | |
static void(^ _mockResultTypeB)(NSString *, NSError *); | |
@implementation Foo | |
/// A: getter / setter | |
+ (NSArray *(^)(void)) mockResultTypeA { | |
return _mockResultTypeA; | |
} | |
+ (void)setMockResultTypeA:(NSArray *(^)(void))value { | |
_mockResultTypeA = value; | |
} | |
/// B: getter / setter | |
+ (void(^)(NSString *, NSError *)) mockResultTypeA { | |
return _mockResultTypeA; | |
} | |
+ (void)setMockResultTypeA:(void(^)(NSString *, NSError *))value { | |
_mockResultTypeA = value; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment