Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
James Lambert
Courses Plus Student 14,477 PointsHow can I load a table from an array in a plist? I need to declare the array empty and can't with out errors.
As simple of an example of what I want as possible.
I have a plist with an array of dictionaries. I can pull from the plist and get the information I want with this code:
var arrayOfDictionariesPath = NSBundle.mainBundle().pathForResource("MyDictionaryList", ofType: "plist") var arrayWithDictionaries = NSArray(contentsOfFile: arrayOfDictionariesPath!)
I am having problems when I want to use the plist to fill a table view. Only because I can seem to declare an empty one globally.
This is the contents of the plist:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <array> <dict> <key>Name</key> <string>John</string> <key>Age</key> <string>15</string> </dict> <dict> <key>Name</key> <string>Audrey</string> <key>Age</key> <string>13</string> </dict> <dict> <key>Name</key> <string>Josh</string> <key>Age</key> <string>9</string> </dict> </array> </plist>
James Lambert
Courses Plus Student 14,477 PointsJames Lambert
Courses Plus Student 14,477 PointsAlso, In objective-c the way to do it was to:
@property (strong, nonatomic) NSArray *tableArray;
and then:
-(NSArray *)tableArray{ if (!_tableArray) { _tableArray = [[NSArray alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"date22" ofType:@"plist"]]; } return _tableArray; }