NSArray initWithContentsOfFile returns nil
ios5, objective-c, xcode4, xcode4.2
Solution
Actually your plist is a dictionary.
Change this:
<dict>
<key>Root</key>
<array>
<string>1</string>
<string>2</string>
</array>
</dict>
to this:
<array>
<string>1</string>
<string>2</string>
</array>
Problem
I'm trying to read a plist file into `NSArray` using `initWithContentsOfFile` as described here My code looks like this ``` NSBundle *bundle = [NSBundle mainBundle]; NSString *plistPath = [bundle pathForResource: @"routes" ofType:@"plist" ]; routes = [[NSArray alloc] initWithContentsOfFile:plistPath ]; NSLog:(@"contents of myArray %@", routes); ``` `routes.plist` has a perfectly simple structure of array and 2 string values inside ``` <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>Root</key> <array> <string>1</string> <string>2</string> </array> </dict> </plist> ``` Everything seems to be fine. `plistPath` initializes with correct value, which means file is copied to the bundle and can be readed. But `routes = [[NSArray alloc] initWithContentsOfFile:plistPath ];` returns `0x0` value. I think this is equal to `nil` What is wrong with my code?