javascript - 查找 Parse 数据库中最常出现的值

标签 javascript ios objective-c mongodb parse-platform

我没有看到关于如何在 Parse 的表中找到最常出现的值的文档。我如何进行此查询(首选 iOS 答案,但不限于)

我想我可以使用某种带有 NSPredicate 的复合查询,但我仍然非常不确定如何进行此计算。

最佳答案

也许这对你有帮助:

NSArray *yourarray = [NSArray arrayWithObjects:@"X", @"Y", @"Z", nil];
NSCountedSet *yourset = [[NSCountedSet alloc] initWithArray:yourarray];

for (id item in yourset) {
    NSLog(@"Count of %@ is %lu", item, (unsigned long)[yourset countForObject:item]);
}

这可能是 NSPredicate 示例(没有尝试,因为我在 TextMate 中编写):

NSDictionary *dic1 = [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:99] forKey:@"visitCount"];
NSDictionary *dic2 = [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:2] forKey:@"visitCount"];
NSDictionary *dic3 = [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:1003] forKey:@"visitCount"];
NSDictionary *dic4 = [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:1005] forKey:@"visitCount"];
NSDictionary *dic5 = [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:107] forKey:@"visitCount"];
NSArray *array = [NSArray arrayWithObjects:dic1, dic2, dic3, dic4, dic5, nil];

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF.visitCount == %@.@max.visitCount", array];

NSArray *result = [array filteredArrayUsingPredicate:predicate];
NSLog(@"Max in objects: %@", result);

关于javascript - 查找 Parse 数据库中最常出现的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30652706/

相关文章:

javascript - jQuery concat 变量输入名称未更新

Javascript Jquery 如何获取 $(this) 对象的名称

iphone - 什么是 key 以及如何使用它们?

objective-c - 从 cocoa mac osx 的根文件夹中删除文件

javascript - 打包node-webkit App

javascript - AWS javascript SDK SES SendMail 非法地址

ios - 以编程方式读取 PDF 嵌入式搜索索引

ios - 无符号整数与 %u

iphone - iOS 简单的方法来转换和存储大表

iphone - 使用 NSTimer 使按钮在一段时间后可见