Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

isaaclimdc

macrumors 6502
Original poster
Can anyone tell me how do I extract and alloc individual values in my plist array of dictionaries to some NSString?

For example, I key in names and their emails:

Code:
<array>
	<dict>
		<key>Name</key>
		<string>John Doe</string>
		<key>Email</key>
		<string>jdoe@gmail.com</string>
	</dict>
	<dict>
		<key>Name</key>
		<string>Alex Smith</string>
		<key>Email</key>
		<string>asmith@gmail.com</string>
	</dict>
</array>

How do I display Alex Smith's email in a text label in some field?
 
Yes I did, but how do i load an array of dictionaries into a single dictionary? i'm pretty confused..
 
Yes I did, but how do i load an array of dictionaries into a single dictionary? i'm pretty confused..

You have to build a new dictionary of dictionaries after deciding on a unique key in your data.

If there is no unique key, stick with the array.
 
Code:
NSArray* plist = [NSArray arrayWithContentsOfFile:pathToPlistFileInMyBundle];

for (NSDictionary*d in plist)
{
     NSString* name = [d objectForKey:@"Name"];
     NSString* email = [d objectForKey:@"Email"];
     // do something with the strings here
}
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.