Reputation: 26223
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
Upvotes: 2
Views: 1442
Reputation: 16857
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 in
keyword conforms to the NSFastEnumeration
protocol, your code is fine.
As a practical matter, since the default implementation in NSEnumerator
just falls through to -nextObject
, you're not likely to see a noticeable difference in speed either way.
Upvotes: 2
Reputation: 26223
Although its often not mentioned you can use fast enumeration on any NSEnumerator object or subclass (NSDirectoryEnumerator) object.
Upvotes: 0