如何判断URL(而不是路径)上是否存在文件,以便在iPhone模拟器中设置预填充的默认存储:
NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"Food.sqlite"];
/*
Set up the store.
For the sake of illustration, provide a pre-populated default store.
*/
NSFileManager *fileManager = [NSFileManager defaultManager];
// If the expected store doesn't exist, copy the default store.
if (![fileManager fileExistsAtPath:storePath]) {
NSString *defaultStorePath = [[NSBundle mainBundle] pathForResource:@"Food" ofType:@"sqlite"];
if (defaultStorePath) {
[fileManager copyItemAtPath:defaultStorePath toPath:storePath error:NULL];
}
}
我了解到,在最新版本的模板中,applicationDocumentsDirectory方法返回一个URL,因此我更改了代码,使用NSURL对象来表示文件路径.但是在[fileManager fileExistsAtPath:storePath]
岁的时候,我需要把fileExistsAtPath
改成fileExistsAtURL
(显然它不存在).
我查看了NSFileManager类参考,没有找到任何适合我的任务.
有什么提示吗?