gpt4 book ai didi

ios - 如何添加objectAtIndex :i of NSArray to NSMutableDictionary

转载 作者:行者123 更新时间:2023-12-01 19:59:59 25 4
gpt4 key购买 nike

如何添加 objectAtIndex:iNSArrayNSMutableDictionary
我试过了

for(int i=0 ;i<=[user count]; i++){

NSMutableDictionary * dict = [NSMutableDictionary :[user objectAtIndex:i]];

}

最佳答案

 NSMutableDictionary *dic = [[NSMutableDictionary alloc] initWithCapacity:[user count]];

for(int i=0 ;i<[user count]; i++) {
[dic setObject:[user objectAtIndex:i] forKey:[NSString stringWithFormat:@"%i", i]];
}

小心这个:i<[user count],就像你现在做的那样,你会得到一条数组索引超出范围的消息。当然,您可以根据需要为每个元素设置键。

关于ios - 如何添加objectAtIndex :i of NSArray to NSMutableDictionary,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40240850/

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