Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // DCIOSObjectArrayConverter.m
- //
- // Created by Rory Sinclair on 13/03/2019.
- // Copyright © 2019 ASMALLWORLD. All rights reserved.
- //
- #import "DCIOSObjectArrayConverter.h"
- #import "IOSObjectArray.h"
- #import "DCDynamicAttribute.h"
- #import "DCNSArrayConverter.h"
- @interface DCIOSObjectArrayConverter()
- @property(nonatomic, strong) DCParserConfiguration *configuration;
- @property(nonatomic, strong) DCNSArrayConverter *arrayConverter;
- @end
- @implementation DCIOSObjectArrayConverter
- @synthesize configuration = _configuration;
- @synthesize arrayConverter = _arrayConverter;
- + (DCIOSObjectArrayConverter *) iOSObjectArrayConverterForConfiguration: (DCParserConfiguration *)configuration {
- return [[self alloc] initWithConfiguration: configuration];
- }
- - (id)initWithConfiguration:(DCParserConfiguration *)configuration{
- self = [super init];
- if (self) {
- self.configuration = configuration;
- self.arrayConverter = [DCNSArrayConverter arrayConverterForConfiguration:self.configuration];
- }
- return self;
- }
- - (id)transformValue:(id)value forDynamicAttribute:(DCDynamicAttribute *)attribute dictionary:(NSDictionary *)dictionary parentObject:(id)parentObject {
- NSMutableArray *result = [NSMutableArray array];
- for (id object in (IOSObjectArray *)value) {
- if (object == nil || object == (id)[NSNull null]) {
- // NSLog(@"Skipping null object in array");
- } else {
- [result addObject:object];
- }
- }
- return [self.arrayConverter transformValue:[NSArray arrayWithArray:result] forDynamicAttribute:attribute dictionary:dictionary parentObject:parentObject];
- }
- - (id)serializeValue:(id)value forDynamicAttribute:(DCDynamicAttribute *)attribute {
- NSException* myException = [NSException
- exceptionWithName:@"NotSupportedException"
- reason:@"serializeValue:forDynamicAttribute without dictionary: and parentObject: is not supported on iOS."
- userInfo:nil];
- @throw myException;
- }
- - (BOOL)canTransformValueForClass:(Class)cls {
- return [cls isSubclassOfClass:[IOSObjectArray class]];
- }
- @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement