Skip to content

Instantly share code, notes, and snippets.

@weekwood
Last active August 29, 2015 14:02
Show Gist options
  • Save weekwood/8ed3318503d7a08873eb to your computer and use it in GitHub Desktop.
Save weekwood/8ed3318503d7a08873eb to your computer and use it in GitHub Desktop.
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