为什么我的 iPhone NSBundle 文件夹中的文件无法删除?
我无法弄清楚为什么 iPhone 应用程序中的文件似乎仍然存在,即使我已经删除了它们。这是给我带来麻烦的代码:
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *bundlePath = [[NSBundle mainBundle] bundlePath];
NSString *folderPath = [bundlePath stringByAppendingPathComponent:@"filefolder"];
NSArray *fileNames = [fileManager contentsOfDirectoryAtPath:folderPath error:NULL];
该代码应该查看文件夹“filefolder”并将其内容读入 fileNames。当我第一次运行这个应用程序时,它会执行此操作。但是,如果我更改文件文件夹的内容(例如,如果我添加或删除文件)并再次构建并运行应用程序,则数组文件名将包含所有新添加的文件的名称(好),但也包含所有文件的名称本来应该被删除的(坏)!
谁能帮助我理解为什么我会看到这种行为?
I'm having trouble figuring out why files in my iPhone app seem to persist, even when I've deleted them. Here's the code that's giving me trouble:
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *bundlePath = [[NSBundle mainBundle] bundlePath];
NSString *folderPath = [bundlePath stringByAppendingPathComponent:@"filefolder"];
NSArray *fileNames = [fileManager contentsOfDirectoryAtPath:folderPath error:NULL];
This code is supposed to look at the folder "filefolder" and read its contents into fileNames. When I run this app the very first time, it will do this. But if I change the contents of filefolder (for instance if I add or delete files) and I build and run the app again, the array filenames will contain names of all the newly added files (good) but also contains names of all the files that were supposed to have been deleted (bad)!!
Can anyone help me understand why I'm seeing this behavior?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从捆绑包中添加/删除新项目后,您是否在 XCode 中进行了“清理”?这通常可以解决“陈旧”资源的问题。
Did you do a "Clean" in XCode after adding/removing new items from the bundle? This usually solves the problem of "stale" resources.