Wednesday, February 29, 2012

Read plist from URL into NSMutableDictionary


I am trying to do read a PLIST from URL to a NSMutableDictionary.



Code before




autos = [[NSMutableArray alloc] init];

[autos addObject:[[NSMutableDictionary alloc]initWithObjectsAndKeys:@"Auto 1", @"name", @"Auto.png", @"image", @"Klassiker", @"description" , nil]];



This works. But now I want to use a PLIST. And I am trying this, this way:




autos = [[NSMutableArray alloc]initWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://dl.dropbox.com/u/9358444/auto.plist"]]];



Thanks.



PLIST http://dl.dropbox.com/u/9358444/auto.plist

2 comments:

  1. Your property list contains a dictionary, but you're trying to use it to instantiate an array. Do this instead:

    NSMutableDictionary *autos = [[NSMutableDictionary alloc] initWithContentsOfURL:
    [NSURL urlWithString:@"http://dl.dropbox.com/u/9358444/auto.plist"]];

    ReplyDelete
  2. I'm new to the site, I'm still not sure how to add comments to the OP. Load it into a dictionary first then transfer it into a mutable array

    ReplyDelete