I am a new Iphone developer i need your help,
Any one provide me creating array with key and value, and how can fetch in xcode.
I am a new Iphone developer i need your help,
Any one provide me creating array with key and value, and how can fetch in xcode.
You can use an
NSDictionary
orNSmutabledictionary
to achieve this you don't need to use andNSArray
. Here is an example of how it works.then you can retrieve a value for a key by just doing.
this will give the value of Value2 in the valueStr string.
to add objects to a none Mutable dictionary
NSDictionary
just dothen just retrieve it the same way as an
NSMutableDictionary
. The difference between the two is that aMutable
dictionary can be modified after creation so can add objects to it with thesetObject:forKey
and remove objects with theremoveObjectFroKey:
whereas the none mutable dictionary can not be modified so once it has been created your stuck with it until it has been released, so no adding or remove objects.Hope this helps.
That's exactly what a NSDictionary / NSMutableDictionary does:
The difference is that, in the mutable one, you can add/modify entries after creating it, but not in the other.
If you don't need to add object anymore, you can create a non mutable dictionary:
If you don't need key value pairs that's an array:
This the NSMutableDictionary. You can search for sample codes. For example: Create dict
Printing all keys and values of a Dict: