Get list of folder and files within Assets.xcassets

南笙酒味 提交于 2019-12-01 22:40:10

问题


I have 2 questions:

  1. I'm adding large amount of mp3 files into Assets.xcassets, is there any performance issue with this?

  2. Within Assets.xcassets, I create folders & sub folders, and put mp3 files in those folders. Now in my code, I want to get list of those folders name and also list of files inside that folder. Is it possible?


回答1:


  1. No it will not hamper your performance. If you face issue with loading large or many files, see this-Is it possible to load a compressed audio file directly into a buffer, without conversion?

  2. Get all folder and subfolder.

For Obj c:

    NSArray *mainpaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,   NSUserDomainMask, YES);
NSString *documentsDir = [mainpaths objectAtIndex:0];

NSFileManager *Filemanager = [NSFileManager defaultManager];
NSArray *fileList = [Filemanager contentsOfDirectoryAtPath:documentsDir error:nil];
for (NSString *s in fileList){
    NSLog(@"YOu subfolder--%@", s);
}

For swift:

    let documentsDirectory =  try! NSFileManager().URLForDirectory(.DocumentDirectory, inDomain: .UserDomainMask, appropriateForURL: nil, create: true)
let fileEnumerator = NSFileManager.defaultManager().enumeratorAtURL(documentsDirectory, includingPropertiesForKeys: nil, options: NSDirectoryEnumerationOptions(), errorHandler: nil)
while let file = fileEnumerator?.nextObject() {
   //get all file name here.
}


来源:https://stackoverflow.com/questions/40077998/get-list-of-folder-and-files-within-assets-xcassets

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