Are there any issues I may be missing using fastEnumeration with the enumerator below? I only ask as code examples (online & books) always seem to use a whileLoop. The code sniped works fine, just curious if I am missing a potential issue. Please not this is just a test with no error checking.
NSDirectoryEnumerator *dirEnum;
NSString *eachPath;
dirEnum = [fileManager enumeratorAtPath:sourceDir];
for(eachPath in dirEnum) NSLog(@"FILE: %@", eachPath);
gary
The examples use a while loop because the fast enumeration syntax is a very recent addition to the language. As long as the object following the
inkeyword conforms to theNSFastEnumerationprotocol, your code is fine.As a practical matter, since the default implementation in
NSEnumeratorjust falls through to-nextObject, you’re not likely to see a noticeable difference in speed either way.