iphone - NSPredicate endswith multiple files -


i trying filter array using predicate checking files ending in set of extensions. how it?

would close '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]     ]]; 

you don't want contains array, want in. ideally want filter path extension. so

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]]; 

Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -