adrianderbaum
adrianderbaum

Reputation: 133

Failing to read array data from a plist - (null) ejected

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 (:

Upvotes: 1

Views: 895

Answers (1)

Flocked
Flocked

Reputation: 1890

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

Upvotes: 3

Related Questions