gpt4 book ai didi

iphone - 插入后 NSMutableDictionary 重新排序元素

转载 作者:行者123 更新时间:2023-11-29 13:37:20 24 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
NSDictionary with ordered keys

我在 iOS 上使用 XMPPFramework,我很惊讶每次插入新的住户/元素时,包含房间住户的 NSDictionary 都会更改其内容的顺序。

这是每次插入后的输出。

<CFBasicHash 0xbccbd60 [0x1f02400]>{type = mutable dict, count = 2,entries =>
1 : <CFString 0xbcd90b0 [0x1f02400]>{contents = "4ee90610e4b08c62894a648c"} = <XMPPRoomOccupant: 0xbcd9360>
2 : <CFString 0xbe5a160 [0x1f02400]>{contents = "4eea53a6e4b08c62894a6c90"} = <XMPPRoomOccupant: 0xbca7cc0>
}

<CFBasicHash 0xbccbd60 [0x1f02400]>{type = mutable dict, count = 3,entries =>
0 : <CFString 0xbe60710 [0x1f02400]>{contents = "4ee8fca3e4b08c62894a6489"} = <XMPPRoomOccupant: 0xbe61370>
1 : <CFString 0xbcd90b0 [0x1f02400]>{contents = "4ee90610e4b08c62894a648c"} = <XMPPRoomOccupant: 0xbcd9360>
2 : <CFString 0xbe5a160 [0x1f02400]>{contents = "4eea53a6e4b08c62894a6c90"} = <XMPPRoomOccupant: 0xbca7cc0>
}

<CFBasicHash 0xbccbd60 [0x1f02400]>{type = mutable dict, count = 4,entries =>
0 : <CFString 0xbe5a160 [0x1f02400]>{contents = "4eea53a6e4b08c62894a6c90"} = <XMPPRoomOccupant: 0xbca7cc0>
4 : <CFString 0xbe71eb0 [0x1f02400]>{contents = "4f7ade44e4b09cb64dc33b90"} = <XMPPRoomOccupant: 0xbe72950>
5 : <CFString 0xbe60710 [0x1f02400]>{contents = "4ee8fca3e4b08c62894a6489"} = <XMPPRoomOccupant: 0xbe61370>
6 : <CFString 0xbcd90b0 [0x1f02400]>{contents = "4ee90610e4b08c62894a648c"} = <XMPPRoomOccupant: 0xbcd9360>
}

正如您在最后一个插入中看到的那样,它改变了 2 个元素的顺序,它也改变了它的索引。这是正常的吗?我查看了代码及其插入使用:

[occupants setObject:occupant forKey:aNickName];

我需要按插入顺序存储元素。而且我还需要通过字符串访问元素。有什么想法吗?

谢谢

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