Soc*_* S. 18 iphone objective-c nspredicate
我试图使用谓词检查以一组扩展名结尾的文件来过滤数组.我怎么能这样做?
接近'自我结束在%@'的工作会有效吗?谢谢!
NSArray * dirContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:documentsDirectoryPath error:nil];
NSArray * files = [dirContents filteredArrayUsingPredicate:
[NSPredicate predicateWithFormat:@"self CONTAINS %@",
[NSArray arrayWithObjects:@".mp4", @".mov", @".m4v", @".pdf", @".doc", @".xls", nil]
]];
Run Code Online (Sandbox Code Playgroud)
Mar*_*ton 63
你不想要数组的包含,你想要的.理想情况下你也希望按路径扩展名进行过滤.所以
NSArray *extensions = [NSArray arrayWithObjects:@"mp4", @"mov", @"m4v", @"pdf", @"doc", @"xls", nil];
NSArray *dirContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:documentsDirectoryPath error:nil];
NSArray *files = [dirContents filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"pathExtension IN %@", extensions]];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9072 次 |
| 最近记录: |