I am using NSDirectoryEnmerator
to find all file with a suffix of png
and jpg
with following code:
NSDirectoryEnumerator *directoryEnumerator = [[NSFileManager defaultManager] enumeratorAtURL:containerURL includingPropertiesForKeys:[NSArray array] options:0 errorHandler:^BOOL(NSURL *url, NSError *error) {
// handle error
return NO;
}];
NSString *fileOrDirectory = nil;
while ((fileOrDirectory = [directoryEnumerator nextObject])) {
if([fileOrDirectory hasSuffix:@".jpg"] || [fileOrDirectory hasSuffix:@".png"]){
NSLog(@" find a image file %@", fileOrDirectory );
}
}
But there is an error said that NSURL
don't have a method hasSuffix
What happened and how to make this work? what does the type of the iterated elements exactly? the above code was frequently suggested by posts and was presumed to be a NSString
but it can't work