I am trying to filter an array using a predicate checking for files ending in a set of extensions. How could I do it?
Would something close to 'self endswith in %@' work? Thanks!
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]
]];
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…