Created
November 13, 2014 05:56
-
-
Save swillits/8c12974e516af04636fc to your computer and use it in GitHub Desktop.
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
// | |
// main.m | |
// Blah | |
// | |
// Created by Seth Willits on 11/12/14. | |
// Copyright (c) 2014 Araelium Group. All rights reserved. | |
// | |
#import <Foundation/Foundation.h> | |
@interface Foo : NSObject | |
@property (readwrite) NSString * __autoreleasing* errorHandle; | |
@property (readwrite, copy) Foo * (^array)(NSString * param, BOOL (^block)(NSString * param, NSString * __autoreleasing* error)); | |
@property (readwrite) BOOL success; | |
@end | |
@implementation Foo | |
- (id)initWithError:(NSString * __autoreleasing *)errorHandle; | |
{ | |
self = [super init]; | |
__weak Foo * weakSelf = self; | |
self.errorHandle = errorHandle; | |
self.array = ^(NSString * param, BOOL (^block)(NSString * param, NSString ** error)){ | |
weakSelf.success = block(param, weakSelf.errorHandle); | |
return weakSelf; | |
}; | |
return self; | |
} | |
@end | |
int main(int argc, const char * argv[]) | |
{ | |
@autoreleasepool { | |
NSString * e = nil; | |
Foo * foo = [[Foo alloc] initWithError:&e]; | |
if (foo.array(@"abc", ^(NSString * param, NSString ** error){ | |
NSArray * comps = [param componentsSeparatedByString:@","]; | |
if (comps.count <= 1) { | |
*error = @"Not an array"; | |
return NO; | |
} else { | |
return YES; | |
} | |
}).success) | |
{ | |
NSLog(@"Success"); | |
} | |
else | |
{ | |
NSLog(@"Failure - %@", e); | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment