gpt4 book ai didi

ios - 将 NSArray 转换为 NSDictionary

转载 作者:行者123 更新时间:2023-11-28 22:42:15 25 4
gpt4 key购买 nike

我想将一个 nsarray 转换为我正在使用的 nsdictionary

- (NSDictionary *) indexKeyedDictionaryFromArray:(NSArray *)array
{
id objectInstance;
NSUInteger indexKey = 0;

NSMutableDictionary *mutableDictionary = [[NSMutableDictionary alloc] init];
for (objectInstance in array)
[mutableDictionary setObject:objectInstance forKey:[NSNumber numberWithUnsignedInt:indexKey++]];

return (NSDictionary *)[mutableDictionary autorelease];
}

输出结果为:

{
0 = {
Event = "";
ID = 1; };
3 = {
Event = "";
ID = 77; };
2 = {
Event = "";
ID = 23; };
1 = {
Event = "";
ID = 45; };
7 = {
Event = "";
ID = 10; };
5 = {
Event = "";
ID = 26; };
6 = {
Event = "";
ID = 27;
};
8 = {
Event = "";
ID = 28;
};
}

转换为nsdictionary后,nsdictionary的顺序与原来的顺序不符,我想在nsarray中显示相同的顺序,我不知道如何?你能帮帮我吗?

最佳答案

NSDictionary 没有顺序。对键进行排序并使用它们来访问条目。

关于ios - 将 NSArray 转换为 NSDictionary,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14179354/

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