Reputation: 91
Struggling with this one. Looking to download a read only plist for use inside my app...
However struggling to read the contents in a Dictionary... Code below, any pointers would be great..
-(void)loadProducts {
NSDictionary *dict = [NSDictionary dictionaryWithContentsOfURL:[NSURL URLWithString:@"https://dl.dropboxusercontent.com/s/f1nmq1wa7gs96dp/Region1Products.plist"]];
for (NSDictionary* productDictionary in dict) {
ProductItem* productItem = [[ProductItem alloc] init];
productItem.picturesCount = [productDictionary objectForKey:@"PicturesCount"];
productItem.maxPicturesCount = [productDictionary objectForKey:@"MaxPicturesCount"];
productItem.size = [productDictionary objectForKey:@"Size"];
productItem.previewImageName = [productDictionary objectForKey:@"ImageName"];
productItem.sequence = [productDictionary objectForKey:@"Sequence"];
productItem.productName = [productDictionary objectForKey:@"Name"];
productItem.type = [productDictionary objectForKey:@"ProductType"];
productItem.prices = [productDictionary objectForKey:@"Prices"];
productItem.shippingPrices = [productDictionary objectForKey:@"ShippingPrices"];
productItem.description = [productDictionary objectForKey:@"Description"];
productItem.popupMessage = [productDictionary objectForKey:@"PopupMessage"];
productItem.popupDetailMessage = [productDictionary objectForKey:@"PopupDetailMessage"];
productItem.incrementalPricing = [[productDictionary objectForKey:@"IncrementalPricing"] boolValue];
if (YES == productItem.incrementalPricing) {
productItem.incrementalPrices = [productDictionary objectForKey:@"IncrementalPrices"];
}
NSArray *previewItems = [productDictionary objectForKey:@"PreviewItems"];
for (NSDictionary* previewItem in previewItems) {
[productItem addProductPreviewItemFromDictionary:previewItem];
}
[self.productsList addObject:productItem];
}
Upvotes: 0
Views: 387
Reputation: 130193
You're creating an NSDictionary from the url, but the top level object in that plist is an array. To solve this, you can change dict
to an NSArray object. I used the following simplified code to test this:
NSArray *array = [NSArray arrayWithContentsOfURL:[NSURL URLWithString:@"https://dl.dropboxusercontent.com/s/f1nmq1wa7gs96dp/Region1Products.plist"]];
for (NSDictionary* productDictionary in array) {
NSLog(@"%@",productDictionary);
}
Upvotes: 1