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

Mockup & CodeGen, iPhone & iPad
($9.99)

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

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 05-26-2008, 02:46 PM   #1 (permalink)
Registered Member
 
Join Date: Apr 2008
Posts: 93
Default Creating an NSArray out of a property list?

Since everything else seems so easy, there has to be an easy way to create an NSArray from something in a property list.

Or a way that you can go
Property list -> NSDictionary -> NSArray
BuschyBoy is offline   Reply With Quote
Old 05-26-2008, 07:37 PM   #2 (permalink)
Registered Member
 
Join Date: Apr 2008
Posts: 93
Default Re: Creating an NSArray out of a property list?

Figured it out!

Sorry!
BuschyBoy is offline   Reply With Quote
Old 05-27-2008, 08:39 AM   #3 (permalink)
New Member
 
Join Date: Apr 2008
Location: Germany
Posts: 154
Default Re: Creating an NSArray out of a property list?

Could you please post a code example showing how you do it?
I can't figure that out myself... :cry:
ChriB is offline   Reply With Quote
Old 05-27-2008, 10:38 AM   #4 (permalink)
Registered Member
 
Join Date: Apr 2008
Posts: 93
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
Old 05-28-2008, 12:09 PM   #5 (permalink)
New Member
 
Join Date: Apr 2008
Location: Germany
Posts: 154
Default Re: Creating an NSArray out of a property list?

Thank you! It's working.
ChriB is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
return list from imdb nownot iPhone SDK Development 3 07-13-2008 03:05 AM
another why: NSDictionary or NSArray (mutable or not) tawpie iPhone SDK Development 8 07-11-2008 11:22 PM
Icon list view? dans iPhone SDK Development 4 07-11-2008 01:01 PM
[Code] Check List Senly iPhone SDK Development 0 05-31-2008 05:55 AM
How to access UIViewController property from its view Eric20000 iPhone SDK Development 5 05-02-2008 10:31 PM


» Advertisements
» Online Users: 244
24 members and 220 guests
ADY, AragornSG, bookesp, chillyh, dacapo, Dani77, Davey555, Dominus, dre, glenn_sayers, HemiMG, JasonR, karlam963, M.A.S., marshusensei, mer10, nobre84, Oral B, prchn4christ, Raggou, Rudy, spiderguy84, themathminister, viniciusdamone
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,885
Threads: 89,230
Posts: 380,765
Top Poster: BrianSlick (7,129)
Welcome to our newest member, bookesp
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:25 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0