我喜欢阅读和解析plist文件,但它无法正常工作。
这是我的代码:NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:self.plistPath];
dict总是(null)
我尝试将内容作为字符串,这是我的代码:
NSString *string = [[NSString alloc] initWithData:[NSData dataWithContentsOfFile:self.plistPath] encoding:NSUTF8StringEncoding];
self.plistPath is /tmp/com.apple.audio.hogmode.plist
这是plist的内容:
<?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/>
</plist>
我做错了什么?
答案 0 :(得分:0)
想出来了!
NSString *error;
NSPropertyListFormat format;
NSDictionary *dict = [NSPropertyListSerialization propertyListFromData:[NSData dataWithContentsOfFile:self.plistPath] mutabilityOption:NSPropertyListImmutable format:&format errorDescription:&error];