gpt4 book ai didi

ios - NSMutableDictionary -- 使用 allKeysforObject 不检索数组值

转载 作者:行者123 更新时间:2023-11-29 04:34:46 25 4
gpt4 key购买 nike

NSMutableDictionary *expense_ArrContents = [[NSMutableDictionary alloc]init];
for (int i = 1; i<=4; i++) {
NSMutableArray *current_row = [NSMutableArray arrayWithObjects:@"payer_id",@"Expense_Type_id",@"Category_Id",@"SubCategory_Id",nil];
[expense_ArrContents setObject:current_row forKey: [NSNumber numberWithInt:i]];
}
NSArray *newArray = [expense_ArrContents allKeysForObject:@"payer_id"];
NSLog(@"%@",[newArray description]);

我想获取包含特定对象的键值列表,该对象位于存储在特定键的 nsmutabledictionary 中的值数组中。

最佳答案

在获取所有键的行 ([expense_ArrContents allKeysForObject:@"payer_id"];) 中,您实际上获取了不在任何数组项中的对象的键。此 @"player_id" 与您在 current_row 中添加的 @"player_id" 是不同的对象。事实上,也许你的所有行都有不同的 @"player_id" 对象(除非编译器进行了一些优化 - 也许它会威胁将相同的字符串文字作为一个对象,而不是为每次迭代创建新对象)。尝试为 @"player_id" 创建一个 NSString 对象,并将其添加到 current_row 中,然后获取同一对象的所有键:

NSString* playerId = @"player_id";
for(){
NSMutableArray *current_row = [NSMutableArray arrayWithObjects: playerId,...];
...
}
NSArray *newArray = [expense_ArrContents allKeysForObject:playerId];

关于ios - NSMutableDictionary -- 使用 allKeysforObject 不检索数组值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11206413/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com