Does the iOS SDK provide queues and stacks?

后端 未结 8 1736
情话喂你
情话喂你 2021-02-02 08:05

I\'m writing an iPhone app, and I\'m surprised that there seem to be no NSQueue or NSStack classes in Apple\'s Foundation Framework. I see that it would be quite easy to roll m

相关标签:
8条回答
  • 2021-02-02 08:34

    Yes, an NSMutableArray doubles as a stack or queue. (It would be slightly inefficient as a queue.)

    You could also use C++'s stack and queue adapter, but it makes memory management a bit messy if you want to store Objective-C objects with it.

    0 讨论(0)
  • 2021-02-02 08:34

    ObjectiveSugar is a very popular CocoaPod that provides, among a bunch of other great stuff, push and pop API calls on NSMutableArray. Sure, it's not in the iOS SDK, but I'm sharing it here because I was looking for the same thing, and this was the solution I went with (and it certainly didn't hurt that we were already using this CocoaPod in our codebase).

    0 讨论(0)
提交回复
热议问题