NSEnumerator problems..

whitesaint

cocoa love
Is NSEnumerator the only way you can switch between objects in an array?
The only method it has is "nextObject" and i think it would be really useful to make a "previousObject" method as well. Does anybody know how to implement this myself? Or more importantly, does anybody know a way to switch to a previous object in an array?
Thanks...

-whitesaint
 
Well, if you know what you're getting, you can always do [theArray objectAtIndex:somenumber];

I suppose if you wanted to go in full revers, you could do this one:

while (i = number of objects in array; anObject=[anArray objectAtIndex:i]; i--)
{
//do something with anObject here
}

But going just one back probably isn't quite as easy. You'd have to keep track of where you are in the array, subract one from that and get the object there, then go back forward to where you were.

Or something like that :D
 
Back
Top