vfn*_*vfn 22
您可以实现以下代码:
NSArray *files = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:
[[NSBundle mainBundle] bundlePath] error:nil];
NSArray *pngs = [files filteredArrayUsingPredicate:
[NSPredicate predicateWithFormat:@"self ENDSWITH[cd] '.png'"]];
NSLog(@"%@", pngs);
Run Code Online (Sandbox Code Playgroud)
运行此代码,您将看到捆绑包上的PNG列表.更改谓词以匹配您想要的前缀:
NSArray *files = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:
[[NSBundle mainBundle] bundlePath] error:nil];
NSArray *filesWithSelectedPrefix = [files filteredArrayUsingPredicate:
[NSPredicate predicateWithFormat:@"self BEGINSWITH[cd] 'prefix'"]];
NSLog(@"%@", filesWithSelectedPrefix);
Run Code Online (Sandbox Code Playgroud)
获取所有文件...
let ff = Bundle.main.urls(forResourcesWithExtension: "png", subdirectory: nil)!
Run Code Online (Sandbox Code Playgroud)
只有 png(比如)...
let ff = Bundle.main.urls(forResourcesWithExtension: "png", subdirectory: nil)!
.compactMap{ $0.lastPathComponent }
Run Code Online (Sandbox Code Playgroud)
以“简”开头的
let ff = Bundle.main.urls(forResourcesWithExtension: "png", subdirectory: nil)!
.compactMap{ $0.lastPathComponent }
.filter{ $0.starts(with: "jane")}
for f in ff { print("filename .. \(f)") }
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3694 次 |
| 最近记录: |