File tree Expand file tree Collapse file tree 2 files changed +12
-11
lines changed
KVC Validation Pattern/KVC Validation Pattern Expand file tree Collapse file tree 2 files changed +12
-11
lines changed Original file line number Diff line number Diff line change @@ -76,9 +76,7 @@ - (NSString*)jsonStringForResponse:(NSUInteger)responseIndex {
76
76
77
77
#pragma mark - UI response
78
78
79
- - (IBAction )viewJSONTapped : (id )sender {
80
- NSLog (@" View JSON tapped" );
81
-
79
+ - (IBAction )viewJSONTapped : (id )sender {
82
80
// toggle source view
83
81
if (self.sourceTextView .hidden == YES ) {
84
82
self.sourceTextView .hidden = NO ;
Original file line number Diff line number Diff line change @@ -33,20 +33,23 @@ - (NSDictionary *)undefinedKeys {
33
33
34
34
- (BOOL )validateHistoricalPrices : (id *)ioValue error : (NSError *__autoreleasing *)outError {
35
35
dispatch_once (&_historyToken, ^{
36
- _historyValidator = [[CTCArrayTypeValidator alloc ] initWithPostValidation: ^NSArray *(id value){
36
+ // if this happens to be a single object (i.e. a dictionary) then assume it was supposed to be an array of one element
37
+ _historyValidator = [[CTCArrayTypeValidator alloc ] initWithDefaultValidation: ^NSArray *(id value, BOOL *isValid, NSError **error){
38
+ if ([value isKindOfClass: [NSDictionary class ]]){
39
+ *isValid = YES ;
40
+ return @[value];
41
+ }
42
+ return nil ;
43
+ }];
44
+
45
+ // take the array we are given and process its contents as CTCHistoricalPrice objects
46
+ _historyValidator.postValidation = ^NSArray *(id value){
37
47
NSMutableArray *histories = [NSMutableArray array ];
38
48
for (NSDictionary *dict in value){
39
49
CTCHistoricalPrice *price = [[CTCHistoricalPrice alloc ] initWithDictionary: dict];
40
50
[histories addObject: price];
41
51
}
42
52
return histories;
43
- }];
44
- _historyValidator.defaultValidation = ^NSArray *(id value, BOOL *isValid, NSError **error){
45
- if ([value isKindOfClass: [NSDictionary class ]]){
46
- *isValid = YES ;
47
- return @[value];
48
- }
49
- return nil ;
50
53
};
51
54
});
52
55
You can’t perform that action at this time.
0 commit comments