Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective-C组和计数不同的条目_Objective C_Group By - Fatal编程技术网

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);
}