Is there something similar to a circular linked list available in Cocoa?
I know that an NSArray is ordered – but I don’t think I can use ‘nextItem’ or ‘previousItem’ – correct? Furthermore, I need the nextItem of the last item to be the first item.
I could add my own nextItem and previousItem methods, but I’m surprised if Apple haven’t implemented something suitable already. I can’t find it though if they have.
While you can certainly use a category to add the behavior to
NSArray(as @darren suggests), it’s possible that you might actually need a true circular buffer. If that’s the case, check out the CHDataStructures framework. Besides a CHCircularBufferStack, there’s also a CHCircularBufferQueue and a CHCircularBufferDeque.