daily pastebin goal
23%
SHARE
TWEET

Untitled

a guest Mar 24th, 2019 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //
  2. //  DCIOSObjectArrayConverter.m
  3. //
  4. //  Created by Rory Sinclair on 13/03/2019.
  5. //  Copyright © 2019 ASMALLWORLD. All rights reserved.
  6. //
  7.  
  8. #import "DCIOSObjectArrayConverter.h"
  9. #import "IOSObjectArray.h"
  10. #import "DCDynamicAttribute.h"
  11. #import "DCNSArrayConverter.h"
  12.  
  13. @interface DCIOSObjectArrayConverter()
  14.  
  15. @property(nonatomic, strong) DCParserConfiguration *configuration;
  16. @property(nonatomic, strong) DCNSArrayConverter *arrayConverter;
  17.  
  18. @end
  19.  
  20. @implementation DCIOSObjectArrayConverter
  21.  
  22. @synthesize configuration = _configuration;
  23. @synthesize arrayConverter = _arrayConverter;
  24.  
  25. + (DCIOSObjectArrayConverter *) iOSObjectArrayConverterForConfiguration: (DCParserConfiguration *)configuration {
  26.     return [[self alloc] initWithConfiguration: configuration];
  27. }
  28.  
  29. - (id)initWithConfiguration:(DCParserConfiguration *)configuration{
  30.     self = [super init];
  31.     if (self) {
  32.         self.configuration = configuration;
  33.         self.arrayConverter = [DCNSArrayConverter arrayConverterForConfiguration:self.configuration];
  34.     }
  35.     return self;
  36. }
  37.  
  38. - (id)transformValue:(id)value forDynamicAttribute:(DCDynamicAttribute *)attribute dictionary:(NSDictionary *)dictionary parentObject:(id)parentObject {
  39.    
  40.     NSMutableArray *result = [NSMutableArray array];
  41.     for (id object in (IOSObjectArray *)value) {
  42.         if (object == nil || object == (id)[NSNull null]) {
  43. //            NSLog(@"Skipping null object in array");
  44.         } else {
  45.             [result addObject:object];
  46.         }
  47.     }
  48.    
  49.     return [self.arrayConverter transformValue:[NSArray arrayWithArray:result] forDynamicAttribute:attribute dictionary:dictionary parentObject:parentObject];
  50. }
  51.  
  52. - (id)serializeValue:(id)value forDynamicAttribute:(DCDynamicAttribute *)attribute {
  53.     NSException* myException = [NSException
  54.                                 exceptionWithName:@"NotSupportedException"
  55.                                 reason:@"serializeValue:forDynamicAttribute without dictionary: and parentObject: is not supported on iOS."
  56.                                 userInfo:nil];
  57.     @throw myException;
  58. }
  59.  
  60. - (BOOL)canTransformValueForClass:(Class)cls {
  61.     return [cls isSubclassOfClass:[IOSObjectArray class]];
  62. }
  63.  
  64. @end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top