views:

149

answers:

1

Hey!

I am currently trying to get data out of a plist.

It basically looks like that:

plist called 'woerter'  
  -> Root key of type Dictionary  
    -> woerter key of type Array  
      -> various Items of type String with string Values

When I now try to read a random string from it, I only get a (null) expression

NSString * path = [[NSBundle mainBundle] bundlePath];
NSString * finalPath = [path stringByAppendingPathComponent:@"woerter.plist"];
NSDictionary * plistData = [[NSDictionary dictionaryWithContentsOfFile:finalPath] retain];
NSArray * array = [plistData valueForKey:@"woerter"];
NSString * string = [array objectAtIndex:arc4random() %110];
NSLog(@"stringtest %@", string);

But all i get is

2010-02-28 23:01:58.911 TypeFast[5606:a0f] stringtest (null)

It is not a problem with arcrandom either since objectAtIndex:2 returns the same.

Where is the problem?

Thank you (:

+2  A: 

You forgot to alloc the NSDictionary and the NSArray, so the array and dictionary can not save the values.

Flocked
Eh? The questioner is creating an NSDictionary from a file, so there is no need to alloc one, and is obtaining the array from the dictionary. There are a couple of reasons why this could fail, but not sending an `alloc` message is not one of them.
Peter Hosey