0

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">
<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?

1 Answer 1

2

You're using temp before it's assigned.

NSMutableArray *temp = [temp initWithContentsOfFile:appFile];

Should be like:

NSMutableArray *temp = [NSMutableArray arrayWithContentsOfFile:appFile];
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks that works great .. didnt spot the Class Method in the documentation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.