Hey Zusammen,
ich habe mal eine Anfänger-Frage bzgl. .plist-Dateien und das Auslesen mehrerer Dictionaries.
Ich dachte ich könnte einfach mit simplen Schleifen immer "tiefer" in meiner plist navigieren.... das scheint aber nicht zu klappen und Google / Suche hier konnte mir nicht weiterhelfen. Ich hoffe ihr könnt mir kurz helfen.
Aufbau meiner Plist:
Alles anzeigen
Mein Code-Schnipsel:
Alles anzeigen
Ich freue mich auf eure Antworten!
Gruß,
Florian
ich habe mal eine Anfänger-Frage bzgl. .plist-Dateien und das Auslesen mehrerer Dictionaries.
Ich dachte ich könnte einfach mit simplen Schleifen immer "tiefer" in meiner plist navigieren.... das scheint aber nicht zu klappen und Google / Suche hier konnte mir nicht weiterhelfen. Ich hoffe ihr könnt mir kurz helfen.
Aufbau meiner Plist:
Quellcode
-
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
- <plist version="1.0">
- <dict>
- <key>1</key>
- <dict>
- <key>id</key>
- <string></string>
- <key>settings</key>
- <dict>
- <key>name</key>
- <string>theName</string>
- <key>image</key>
- <string>imageName</string>
- </dict>
- </dict>
- <key>2</key>
- <dict>
- <key>id</key>
- <integer>2</integer>
- <key>settings</key>
- <dict>
- <key>name</key>
- <string>theName2</string>
- <key>image2</key>
- <string>imageName</string>
- </dict>
- </dict>
- </dict>
- </plist>
Mein Code-Schnipsel:
Quellcode
-
- NSString* plistPath = [[NSBundle mainBundle] pathForResource:@"plist" ofType:@"plist"];
- NSDictionary* contentArray = [NSDictionary dictionaryWithContentsOfFile:plistPath];
- NSLog(@"contentArray %@",contentArray);
- for (NSDictionary* dict in contentArray) {
- NSLog(@"dict: %@",dict);
- NSDictionary *first = [dict objectForKey:@"1"];
- for (NSDictionary* firstDict in first) {
- NSLog(@"firstDict: %@",firstDict);
- NSDictionary *settingsDict = [dict objectForKey:@"settings"];
- for (NSDictionary* settings in settingsDict) {
- NSLog(@"settings: %@",settings);
- }
- }
- }
Ich freue mich auf eure Antworten!
Gruß,
Florian