Objective-C组和计数不同的条目
这是一个核心功能问题。我总是在数据库方面处理这个问题,因为我不能为这个案子做这件事,我被难住了。我想计算不同的值。假设我有一个数组Objective-C组和计数不同的条目,objective-c,group-by,Objective C,Group By,这是一个核心功能问题。我总是在数据库方面处理这个问题,因为我不能为这个案子做这件事,我被难住了。我想计算不同的值。假设我有一个数组 Array = {a,a,a,a,b,b,b,b,c,c,c,c} 我想要的只是得到 Result = {[a,4],[b,4],[c,4]} or ResultDistinct = { a, b, c} , ResultCount = {4,4,4} 我可以使用任何格式,只要它快速、整洁。使用NSCountedSet NSArray *myArray =
Array = {a,a,a,a,b,b,b,b,c,c,c,c}
我想要的只是得到
Result = {[a,4],[b,4],[c,4]} or
ResultDistinct = { a, b, c} , ResultCount = {4,4,4}
我可以使用任何格式,只要它快速、整洁。使用
NSCountedSet
NSArray *myArray = ... // array with all the a, b, and c values
NSCountedSet *set = [[NSCountedSet alloc] initWithArray:myArray];
for (id obj in set) {
NSLog(@"There are %d instances of %@", [set countForObject:obj], obj);
}
使用
NSCountedSet
NSArray *myArray = ... // array with all the a, b, and c values
NSCountedSet *set = [[NSCountedSet alloc] initWithArray:myArray];
for (id obj in set) {
NSLog(@"There are %d instances of %@", [set countForObject:obj], obj);
}
使用
NSCountedSet
NSArray *myArray = ... // array with all the a, b, and c values
NSCountedSet *set = [[NSCountedSet alloc] initWithArray:myArray];
for (id obj in set) {
NSLog(@"There are %d instances of %@", [set countForObject:obj], obj);
}
使用
NSCountedSet
NSArray *myArray = ... // array with all the a, b, and c values
NSCountedSet *set = [[NSCountedSet alloc] initWithArray:myArray];
for (id obj in set) {
NSLog(@"There are %d instances of %@", [set countForObject:obj], obj);
}