gpt4 book ai didi

cocoa - 为什么 NSFileManager 不工作?

转载 作者:行者123 更新时间:2023-12-03 17:28:22 24 4
gpt4 key购买 nike

我编写了一些代码来将文件 (dbtemplate.sqlite) 从应用程序包复制到库。但是,库中没有显示任何文件,每次启动应用程序时,它都会记录复制模板的文本。控制台中没有显示任何错误。我做错了什么?

NSFileManager *fileManager = [NSFileManager defaultManager];

if (![fileManager fileExistsAtPath:@"~/Library/AppSafe/database/db.sqlite"]) {

[fileManager createDirectoryAtPath:@"~/Library/AppSafe/database" withIntermediateDirectories:YES attributes:nil error:nil];

[fileManager copyItemAtPath:@"dbtemplate.sqlite" toPath:@"~/Library/AppSafe/database/db.sqlite" error:nil];
NSLog(@"copied template");

}

最佳答案

如果我没记错的话,您必须将完整路径传递到 NSFileManager 方法中,并且使用波浪号前缀的路径将不起作用。

因此,不要使用 @"~/Library/...",而是使用:

[@"~/Library/..." stringByExpandingTildeInPath]

关于cocoa - 为什么 NSFileManager 不工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7139185/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com