Getting iPhone mainBundle Files

China☆狼群 提交于 2020-01-01 09:13:10

问题


I dont know the exact code i need to retrieve all of the filenames of the resources in my iphone apps mainBundle. if i could have some kind of code like:

  NSArray *array = [[NSBundle mainBundle] getAllResourceFilenames];

it would be helpful. thanks inadvanced for any help!


回答1:


You should look at the SDK documentation for NSFileManager, but this will get you started:

NSString *path = [[NSBundle mainBundle] resourcePath];
NSFileManager *fm = [NSFileManager defaultManager];

NSError *error = nil;

NSArray *directoryAndFileNames = [fm contentsOfDirectoryAtPath:path error:&error];



回答2:


You can get the resources path of the main bundle

[[NSBundle mainBundle] resourcePath];

and then simply use the regular NSFileManager methods to get its contents.



来源:https://stackoverflow.com/questions/3428715/getting-iphone-mainbundle-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!