本文介绍了iOS将文件从主包复制到文档目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图将我添加到名为includes的文件夹中的文件复制到文档目录中也称为includes的文件夹中。我得到resContents nil值。为什么?谢谢
I am trying to copy files that I add to a folder called "includes" to a folder on documents directory called also "includes". I get for resContents nil value. Why? Thank you
- (void)copyResources{
NSString *sourcePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"includes"];
NSString *destPath = [[self applicationDocumentsDirectory] stringByAppendingPathComponent:@"includes"];
NSArray* resContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:sourcePath error:NULL];
for (NSString* obj in resContents){
NSError* error;
if (![[NSFileManager defaultManager] copyItemAtPath:[sourcePath stringByAppendingPathComponent:obj] toPath:[destPath stringByAppendingPathComponent:obj]
error:&error])
NSLog(@"Error: %@", error);;
}
}
推荐答案
您应该将包含
文件夹作为文件夹引用添加到您的Xcode项目中,而不是一个组。
You should add to your Xcode project your includes
folder as a folder reference and not a group.
组只是为了保持组织,而不是提供文件夹结构,因此,当复制到设备,所有的文件结束在同一级别。
Groups are just meant to keep things organized rather than provide a folder structure and therefore when copying to the device, all the files end up at the same level.
这篇关于iOS将文件从主包复制到文档目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!