I am facing the problem to insert the data into dictionary.
It is not saving data in the order I had given to it.
For this dictionary I am giving one keys array and one values array like this.
both arrItemDetails and arrItemNames are NSMutableArray instances
NSArray *detailsArray = [NSArray arrayWithArray:arrItemDetails];
NSArray *namesArray = [NSArray arrayWithArray:arrItemNames];
NSDictionary *dictWithItemNamesAndDetails = [NSDictionary dictionaryWithObjects:arrItemDetails forKeys:arrItemNames];
But for my app I need to maintain order, so please help me regarding this.
I am giving outputs of namesArray (keys) and detailsArray (valuesarray) and after adding them how the dictionary is also kk
Printing description of arrItemDetails:
(
hi,
44,
5,
555,
3
)
Printing description of arrItemNames:
(
CardName,
AccessNumber,
AccessPause,
Pin,
Pause
)
Printing description of dictWithItemNamesAndDetails:
<CFBasicHash 0x6a90680 [0x274b380]>{type = immutable dict, count = 5,
entries =>
0 : <CFString 0xe3b4 [0x274b380]>{contents = "AccessNumber"} = <CFString 0x6d25970 [0x274b380]>{contents = "44"}
1 : <CFString 0xe394 [0x274b380]>{contents = "Pin"} = <CFString 0x6d3cda0 [0x274b380]>{contents = "555"}
3 : <CFString 0xe384 [0x274b380]>{contents = "Pause"} = <CFString 0x6d37080 [0x274b380]>{contents = "3"}
5 : <CFString 0xe3a4 [0x274b380]>{contents = "AccessPause"} = <CFString 0x6d6c250 [0x274b380]>{contents = "5"}
6 : <CFString 0xe3c4 [0x274b380]>{contents = "CardName"} = <CFString 0x6d56c70 [0x274b380]>{contents = "hi"}
}
I want to store data in needed order. This is my main concern.
A dictionary is not an ordered/indexed data structure. It is a key/value paired data structure. You can not guarantee the order of the keys. And after inserting new key/value the previous order might change. If you want to use dictionary, then you need to use keys to access the values, not any kind of index.