I have a plist like this:
<dict>
<key>New item</key>
<dict>
<key>document</key>
<string>driving licence</string>
<key>Overview</key>
<string>a driving licence is required.......</string>
</dict>
if I want to get the object I would write something like this:
myString = [somedictionary objectForKey:@"Overview"];
what about if I want to get "overview" from my plist??? I Hope it's clear..... Please do not give negative vote.... I'm still learning!;-)
EDITED VERSION:
Better to be more specific:
i have this code
for (NSDictionary *playDictionary in playDictionariesArray) {
Play *play = [[Play alloc] init];
play.name = [playDictionary objectForKey:@"playName"];
which is the Apple sample code: http://developer.apple.com/library/ios/#samplecode/TableViewUpdates/Introduction/Intro.html
In this sample the string play return the name of the play in the header section but I want to modify it and get the "Key" in the header (in this case would be "PlayName).
THANKS TO EVERYBODY: THIS IS HOW I FIXED IT:
NSMutableArray *anArray = [[NSMutableArray alloc] init];
[anArray addObject:@"Overview"];
[anArray addObject:@"pre-requirements"];
[anArray addObject:@"where"];
[anArray addObject:@"what"];
//Use a for each loop to iterate through the array
for (NSString *s in anArray) {
Play *play = [[Play alloc] init];
play.name = s;
You have to convert NSDictionary to NSMutableDictionary . You have to user NSMutableDictionary in place of the NSDictionary . After that you can able to change value in NSMutableDictionary .
An object representing a dynamic collection of key-value pairs, for use instead of a Dictionary variable in cases that require reference semantics.
An NSDictionary will retain it's objects, and copy it's keys.
Creating NSDictionary Objects Using Dictionary Literals In addition to the provided initializers, such as init(objects:forKeys:) , you can create an NSDictionary object using a dictionary literal. In Objective-C, the compiler generates code that makes an underlying call to the init(objects:forKeys:count:) method.
You can get an array of all the keys in the dictionary using [dict allKeys]
. You can get an array of all keys whose value is a specific object using [dict allKeysForObject:object]
. You can process the keys one-by-one in a loop like this:
for (NSString *key in dict) {
...
}
try this and if it works let me know..
NSMutableArray* result = [NSMutableArray array];
for (NSString* key in dictionary) {
[result addObject:key];
// write to a dictionary instead of an array
// if you want to keep the keys too.
}
return result;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With