Last active
August 29, 2015 14:02
-
-
Save weekwood/8ed3318503d7a08873eb to your computer and use it in GitHub Desktop.
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
NSMutableArray *resultArray = [NSMutableArray new]; | |
NSArray *groups = [self.survey.questions valueForKeyPath:@"@distinctUnionOfObjects.type"]; | |
for (NSString *groupId in groups) | |
{ | |
NSMutableDictionary *entry = [NSMutableDictionary new]; | |
[entry setObject:groupId forKey:@"type"]; | |
NSArray *groupNames = [self.survey.questions filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"type = %@", groupId]]; | |
[entry setObject:groupNames forKey:@"values"]; | |
[resultArray addObject:entry]; | |
} | |
NSMutableArray *finalArr = [@[] mutableCopy]; | |
[resultArray enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { | |
NSMutableDictionary *values = obj; | |
if([values[@"type"] isEqualToString:@"单选"]){ | |
NSArray *arr = values[@"values"]; | |
[values setObject:[NSArray splitArray:arr componentsPerSegment:5] forKey:@"values"]; | |
} | |
if([values[@"type"] isEqualToString:@"问答"] || [values[@"type"] isEqualToString:@"多选"] ){ | |
NSArray *arr = values[@"values"]; | |
[values setObject:[NSArray splitArray:arr componentsPerSegment:1] forKey:@"values"]; | |
} | |
[values[@"values"] enumerateObjectsUsingBlock:^(id objArr, NSUInteger idxArr, BOOL *stopArr) { | |
[finalArr addObject:objArr]; | |
}]; | |
}]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment