Re: reading keys from a plist file
Re: reading keys from a plist file
- Subject: Re: reading keys from a plist file
- From: "M. Uli Kusterer" <email@hidden>
- Date: Mon, 1 Dec 2003 11:44:44 +0100
At 2:16 Uhr -0800 01.12.2003, Tavis wrote:
<plist version="1.0">
<dict>
<key>AppleSymbolicHotKeys</key>
<dict>
<key>32</key>
<dict>
<key>enabled</key>
<true/>
<key>value</key>
<dict>
<key>parameters</key>
<array>
<integer>-1</integer>
<integer>101</integer> //I
want this integer
<integer>0</integer>
</array>
<key>type</key>
<string>standard</string>
</dict>
</dict>
<...>
NSDictionary *loginItemDict = [NSDictionary
dictionaryWithContentsOfFile:[NSString
stringWithFormat:@"%@/Library/Preferences/
com.apple.symbolichotkeys.plist", NSHomeDirectory()]];
NSEnumerator *loginItemEnumerator = [[loginItemDict
objectForKey:@"AppleSymbolicHotKeys"] objectEnumerator];
Remember that this is just a nestesd structure of objects. So,
looking at the XML we have:
NSDictionary:
AppleSymbolicHotkeys: NSDictionary
32: NSDictionary
enabled: NSBoolean "true"
value: NSDictionary
parameters: NSArray
0: NSNumber "-1"
1: NSNumber "101"
2: NSNumber "0"
type: NSString "standard"
So, what you do is just ask each object to contain the specified
entry, and then treat that sub-entry as a new object of the type it
has in the list above, e.g.
symHotkeysDict = [loginItemDict objectForKey: @"AppleSymbolicHotkeys"];
thirtyTwoHotkeysDict = [symHotkeysDict objectForKey: @"32"];
...
NSNumber* secondNumber = [parametersArray objectAtIndex: 1];
And now you just use any NSNumber method to get the number out of the
object secondNumber as the C type you want.
You don't need an NSEnumerator if that's all you want to do.
NSEnumerators are only for the case where you want to enumerate all
(or most) of the objects in an array, dictionary or whatever. In
particular, since AppleSymbolicHotkeys above again contains a
dictionary, I don't think you can use objectEnumerator on it (as I
seem to remember that method only was available for NSArray).
--
Cheers,
M. Uli Kusterer
------------------------------------------------------------
"The Witnesses of TeachText are everywhere..."
http://www.zathras.de
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.