ios - 数组中的 NSDictionary allKeysForObject

标签 ios objective-c

我有一个看起来像这样的 NSDictonary。我需要获取与特定名称关联的所有键值。例如,名称 Samrin 与键 11.titleKey、110.titleKey 等相关联。我遇到的问题是我不确定如何获取数组中的对象然后将它们的键值传回?

我尝试了以下代码,但收效甚微。

enter image description here

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *stringsPlistPath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"birthdays.plist"];
    NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] initWithContentsOfFile:stringsPlistPath];

    NSArray *temp = [dictionary allKeysForObject:@"Samrin Ateequi"];
    NSLog(@"temp: %@ ...", temp);

OUTPUT: 
temp: (
) ...

最佳答案

我认为您可以为此使用 keysOfEntriesPassingTest。像这样的东西:

NSSet *keysSet = [dictionary keysOfEntriesPassingTest:^(id key, id obj, BOOL *stop) {
                 if ([[obj objectAtIndex:0] isEqualToString:@"Samrin Ateequi"]) {
                     return YES;
                 } else {
                     return NO;
                 }
}];

关于ios - 数组中的 NSDictionary allKeysForObject,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24657976/

相关文章:

iphone - 自定义委托(delegate)未接听电话

android - Adobe Air Mobile(iOS、Android)和来电

ios - 通过从应用程序图标启动,在应用程序完全关闭时处理远程通知

ios - 如何使用滑动菜单为单个 View 设置横向?

iOS 验证开发者的应用商店购买 ID

ios - AVFoundation 将第一帧添加到视频

ios - 从 SKTileMapNode 中删除特定图 block

ios - 设置 layer.borderColor 时 UICollectionViewCell 边框消失

ios - PushViewController 导致黑屏,没有 Storyboard

ios - 自动布局不适用于 iOS7 和 Xcode 6