Reputation: 109
Hi i'm fairly new to objC and i am hoping someone can help me out.
I 'm making a sample location app. It has a plist with locationNames and coordinates. i have read the plist into a NSDictionary, i am also using an NSarray with allkeys to return the keys.
Each key contains 2 stings, i want to be able to specifically return 1 of them.
This is my plist:
<dict>
<key>orleans</key>
<dict>
<key>lat</key>
<string>100192</string>
<key>lon</key>
<string>990099</string>
</dict>
<key>arras</key>
<dict>
<key>lon</key>
<string>122121</string>
<key>lat</key>
<string>878737</string>
</dict>
</dict>
This is my code:
NSString *myFile = [[NSBundle mainBundle]
pathForResource:@"vluchten" ofType:@"plist"];
coordinaten = [[NSDictionary alloc]initWithContentsOfFile:myFile];
vluchten = [coordinaten allKeys];
NSLog(@"coordinaat lon :%@" ,[coordinaten objectForKey:[vluchten objectAtIndex:1]]);
-- which returns:
2012-06-22 19:39:27.075 Pigeons[6817:11603] coordinaat lon :{
lat = 100192;
lon = 990099;
}
And i only want the lat value returned (lon i want later)
I hope someone can help me out here please.
Greetings, jaco
Upvotes: 0
Views: 408
Reputation: 31016
Your plist defines a dictionary where each member is also a dictionary, so:
NSDictionary *arras = [coordinaten objectForKey:[vluchten objectAtIndex:1]];
NSString *arrasLat = [arras objectForKey:@"lat"];
Upvotes: 2