我正在尝试使用编码文件(做一个教程)。无论如何,我试图保存一个名为“Checklists.plist”的文件,但在我的应用位置找不到它:
USERINFOSTUFF /图书馆/应用支持/ iPhone模拟器/ 7.0.3 /应用程序/ APP号码 /Library/Documentation/Checklists.plist
另外,当我试图取消隐藏它时,库中的文档文件夹根据终端不存在,即使Xcode说它确实存在...
大胆只是为了摆脱行话。这是代码:
- (NSString *)documentsDirectory
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentationDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
return documentsDirectory;
}
-(NSString *)dataFilePath
{
return [[self documentsDirectory] stringByAppendingPathComponent:@"Checklists.plist"];
}
-(void)saveChecklistItems
{
NSMutableData *data = [[NSMutableData alloc] init];
NSKeyedArchiver *archiever = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];
[archiever encodeObject:items forKey:@"ChecklistItems"];
[archiever finishEncoding];
[data writeToFile:[self dataFilePath] atomically:YES];
}
我使用了以下路径:
NSLog(@"Document is at: %@", [self documentsDirectory]);
NSLog(@"Data file path is at: %@", [self dataFilePath]);
答案 0 :(得分:0)
更改:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentationDirectory, NSUserDomainMask, YES);
到此:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);