我正在尝试从文件初始化数组
这是包含字符串数组的文件..这是xml文件
<?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>
我正在尝试此代码
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];
在调试时,我看到应用程序文件名正确并且文件存在。 但是数组没有填充任何对象?
我在这里做错了什么?
答案 0 :(得分:2)
您在分配之前使用temp
。
NSMutableArray *temp = [temp initWithContentsOfFile:appFile];
应该像:
NSMutableArray *temp = [NSMutableArray arrayWithContentsOfFile:appFile];