Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
有没有一种有效的方法可以将对象添加到 的开头NSMutableArray?我正在寻找一个好的双端队列objective C也可以。
NSMutableArray
objective C
简单地
[array insertObject:obj atIndex:0];
检查文档
正如其他答案所指出的,只需使用该insertObject:atIndex方法。它是高效的,因为 NSArrays 不一定由连续的内存组成,即当插入发生时元素并不总是被移动,特别是对于大型数组,即几十万个元素。请参阅此博客另请注意,在目标 C 中,仅指针在数组中移动,因此 memmove 可以在内部使用,这与必须制作副本的 C++ 不同。
insertObject:atIndex
还有这个SE问题。