Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 05-27-2008, 09:38 AM   #4 (permalink)
BuschyBoy
Registered Member
 
Join Date: Apr 2008
Posts: 93
BuschyBoy is an unknown quantity at this point
Default Re: Creating an NSArray out of a property list?

I did it like this:
Code:
NSString *thePList = [[NSBundle mainBundle]  pathForResource:@"YourInfo" ofType:@"plist"];  //Change YourInfo to the name of the plist file
NSArray *rawElementsArray = [[NSArray alloc] initWithContentsOfFile:thePList]; //Creates an array out of the PList
NSArray *theArray; // An NSArray to use as self.list if using in the tableview.

NSMutableDictionary *eachDictionary; //Create a dictionary for the for loop.
NSMutableArray *anArray = [[NSMutableArray alloc] init]; // And a mutable array for the for loop
	
for(eachDictionary in rawElementsArray) { //For every dictionary that's in the PList's array
	YourObject *aObject = [[YourObject alloc] initWithDictionary:eachDictionary]; // Have this be an NSObject
	[anArray addObject:aObject.parameter]; // Again simply if you're using a tableview for a list
}
	
theArray = [[NSArray alloc] initWithArray:anArray];
Then the self.list would just be set to "theArray" if you wanted it to populate a tableview.

If you need help with the NSObject let me know, but the Simple Drill Down really helped me with that part.
BuschyBoy is offline   Reply With Quote
 

» Advertisements
» Stats
Members: 175,637
Threads: 94,101
Posts: 402,822
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jessicagx69
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 11:31 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.