Re: Efficiently iterating files on the iPhone
Re: Efficiently iterating files on the iPhone
- Subject: Re: Efficiently iterating files on the iPhone
- From: Chris Parker <email@hidden>
- Date: Wed, 14 Apr 2010 13:42:57 -0700
On 14 Apr 2010, at 12:39 PM, Dave DeLong wrote:
> I'm trying to find a fast and efficient way to iterate a folder on the iPhone. On the Mac, I'd create an FSIterator and use FSGetCatalogInfoBulk (so I can retrieve permissions, file type, resource/data fork size, etc). However, FSIterator and FSGetCatalogInfo* are part of the CoreServices framework, which doesn't appear to exist on the device (although it's in the simulator SDK).
The simulator SDK doesn't reflect what actually happens on the device. Trust what's in (or what isn't in) the device SDK.
> If I have to, I can use the NSFileManager APIs, but then I'd have to grab the entire directory listing at once (instead of getting it in chunks), and then iteratively ask for each item's attributes. It seems rather inefficient, and I want to make this as efficient as possible. (NSFileManager also does not include resource forks)
You're on the iPhone; resource forks aren't something you need to worry about - even though the filesystem may be HFS+, it's not as if you can read a resource fork on the device. As Jens implies, this sounds like you're prematurely optimizing a bit.
> Any suggestions on how I can iterate a directory and get file information at the same time?
The current implementation of NSFileManager on the iPhone should be pretty efficient about the available information because it's basically using what's available in the stat() block and nothing else.
You should be fine in just using NSFileManager and asking for fileAttributes using an NSDirectoryEnumerator. And as that gets faster, you'll get faster. If you're that worried about it, though, it implies you have a ton of files you're iterating over. Is that really the case?
.chris
--
Chris Parker
iPhone Frameworks
Apple, Inc.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden