I’m trying to learn how to read from a plist… mine is a simple case. I really just want to read one integer, although for a more general case of data I would appreciate advice as well. The plist has Item0 – Array, and under that Item 0 with a number. This is how I’m trying to read this.
plistArray = [[NSArray alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://www.website.com/count.plist"]];
//count = [[plistArray objectAtIndex:0]];
count=(int)[plistArray objectAtIndex:0];
NSLog(@"array %@\n",plistArray);
NSLog(@"count %i\n",count);
This is the plist xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "apple.com/DTDs/PropertyList-1.0.dtd">
;<plist version="1.0">
<dict>
<key>Item0</key>
<array>
<integer>12</integer>
</array>
</dict>
</plist>
There are two problems with the plist:
;in front of the<plist>tag should not be thereFirst, remove the semi-colon.
Next, either update the plist to contain only the
<array>element or update the code to first read the<dict>and then take theNSArrayfrom the dictionary: