Re: Count of enumerator?
Re: Count of enumerator?
- Subject: Re: Count of enumerator?
- From: John Stiles <email@hidden>
- Date: Thu, 11 May 2006 08:17:53 -0700
I think NSEnumerators are designed such that they don't know how many
items are inside; they can just walk. That's a performance/functionality
tradeoff.
e.g. imagine if you wanted to make an NSEnumerator of the whole file
system (just for the sake of a simple explanation). With the current
design, it doesn't need to grab the state of the entire disk when you
first create it; it only needs to know where it's currently pointing in
the file system hierarchy, and how to find the next thing. If it
supported -[count], then it would need to count up every file on the
hard disk all at once.
I think the best way to get a count is what you're doing now. It's
probably not too expensive if you're not counting gargantuan numbers of
items.
Christopher Hickman wrote:
Is it possible to get a count of an enumerator without exhausting it? I
just want to know how many objects remain in my enumerator, but calling
allObjects to get a count exhausts it. I can work around by doing some
silly things like creating a new enumerator from the array returned by
allObjects after counting it, but it seems like there should be a simpler
way. (Plus, I lose functionality from that since -[NSArray objectEnumerator]
returns an NSEnumerator and I'm starting with an NSDirectoryEnumerator.
I guess I might just have to file an enhancement request against Foundation
to add -[NSEnumerator count], but I'm hoping there's just something I'm
missing.
Topher
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden