views:

14

answers:

1

Hi, I am trying to initialise an array from a file

This is the file containing an array of strings .. this is the xml file

<?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"&gt;
<plist version="1.0">
<array>
<string>ccccc</string>
<string>ddddddd</string>
</array>
</plist>

I am trying this code

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);   
NSString *documentsDirectory = [paths objectAtIndex:0];   
NSString *appFile = [documentsDirectory stringByAppendingPathComponent:@"settings-02.xml"];   
NSLog(@"%@",appFile); // debug
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:appFile]; // debug
NSMutableArray *temp = [temp initWithContentsOfFile:appFile];

On debugging I see that the app file name is correct and that the file exists. However the array does not get populated with any objects?

What am I doing wrong here?

A: 

You're using temp before it's assigned.

NSMutableArray *temp = [temp initWithContentsOfFile:appFile];

Should be like:

NSMutableArray *temp = [NSMutableArray arrayWithContentsOfFile:appFile];
Eonil
Thanks that works great .. didnt spot the Class Method in the documentation.
Philip Bevan