【发布时间】:2013-05-07 05:31:38
【问题描述】:
为不同信息创建多个 Plist 路径的程序。
但只有一条路径不起作用。 (我认为“writeToFile”是问题所在)
代码:
-(NSString *) createPath:(NSString *)withFileName
{
NSArray *paths =NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,
YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:withFileName];
return path;
}
路径
NSLog = /var/mobile/Applications/02CABC0A-6B5B-4097-A9D1-4336BE8230B7/Documents/MessagesDB.plist
&
-(void) messagesDbFlush
{
// save it to the file for persistency
NSString *messagesDB_Path = [self createPath:_fileMessagesDB];
[_messagesDB writeToFile:messagesDB_Path atomically:YES];
NSMutableArray *ReturnsInfo = [[NSMutableArray alloc ]initWithContentsOfFile:messagesDB_Path];
NSLog(@"ReturnsInfo is : %@", ReturnsInfo);
}
“ReturnsInfo”数组为空:/
有人帮忙吗?
【问题讨论】:
-
艾哈迈德和马尤尔,感谢您的编辑
-
writeToFile:atomically: 返回一个 BOOL,它是什么? _messagesDB 是一个数组吗?
-
检查您的 plist 实际上是一个数组。它可能是一本字典。
标签: objective-c plist nsfilemanager writetofile