我们如何从资源文件夹中获取以前缀开头的所有文件名。
您可以通过调整以下代码来实现:
NSArray *files = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:
[[NSBundle mainBundle] bundlePath] error:nil];
NSArray *pngs = [files filteredArrayUsingPredicate:
[NSPredicate predicateWithFormat:@"self ENDSWITH[cd] '.png'"]];
NSLog(@"%@", pngs);
运行此代码,您将在包中看到 PNG 列表。更改谓词以与所需的前缀匹配:
NSArray *files = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:
[[NSBundle mainBundle] bundlePath] error:nil];
NSArray *filesWithSelectedPrefix = [files filteredArrayUsingPredicate:
[NSPredicate predicateWithFormat:@"self BEGINSWITH[cd] 'prefix'"]];
NSLog(@"%@", filesWithSelectedPrefix);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)