【发布时间】:2011-08-27 11:30:19
【问题描述】:
我有以下代码
for (int j= 0; j<data.count; j++){
NSString *thedata = [data objectAtIndex:j];
NSMutableDictionary * booksList = [NSMutableDictionary dictionary];
if(j==0){
[booksList setValue:[NSString stringWithFormat:@"%@",thedata] forKey:@"name"];
}
if(j==1){
[booksList setValue:[NSString stringWithFormat:@"%@",thedata] forKey:@"author"];
}
[plistDict setObject:booksList forKey:@"Categories"];
[plistDict writeToFile:pListPath atomically: YES];
}
此代码假设将 booksList 保存到名为 categories 的键中的 plist 中。这里发生的情况是,键类别被清空,就好像我正在向它写入 null 一样。我已经记录了 booksList 和它返回
> 2011-08-27 14:22:15.821 SparkLibrary[8306:13403] {
name = "\"dark matter\"";
}
2011-08-27 14:22:15.823 SparkLibrary[8306:13403] {
author = "\"tamer ibrahim\"";
}
2011-08-27 14:22:15.824 SparkLibrary[8306:13403] {
}
2011-08-27 14:22:15.825 SparkLibrary[8306:13403] {
}
2011-08-27 14:22:15.826 SparkLibrary[8306:13403] {
}
2011-08-27 14:22:16.915 SparkLibrary[8306:13403] {
name = "\"crypt tales\"";
}
2011-08-27 14:22:16.917 SparkLibrary[8306:13403] {
author = "\"tamer ibrahim\"";
}
2011-08-27 14:22:16.918 SparkLibrary[8306:13403] {
}
2011-08-27 14:22:16.919 SparkLibrary[8306:13403] {
}
2011-08-27 14:22:16.920 SparkLibrary[8306:13403] {
}
那么有什么问题可以帮忙吗?
【问题讨论】:
标签: iphone plist nsmutabledictionary