本文介绍了如何获得可可中NSArray的前x个元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可可的新手,似乎缺少了一些东西.
New to Cocoa, and seem to be missing something.
将NSArray
的前x个元素用作另一个NSArray
的最优雅/惯用的方法是什么?显然,我可以遍历它们并手动存储它们,但是似乎必须有一种更标准的方法来执行此操作.
What is the most elegant/idiomatic way to obtain the first x elements of an NSArray
as another NSArray
? Obviously I can iterate through them and store them manually, but it seems like there has to be a more standard method of doing this.
我期望有一个-arrayWithObjectsInRange:
或类似的东西,但是什么也看不到...
I was expecting there to be an -arrayWithObjectsInRange:
or something similar, but don't see anything...
NSArray* largeArray...// Contains 50 items...
NSArray* smallArray = // fill in the blank
// smallArray contains first 10 items from largeArray
谢谢!
推荐答案
您可以使用 subarrayWithRange:
.
You can use subarrayWithRange:
.
NSArray *smallArray = [largeArray subarrayWithRange:NSMakeRange(0, 10)];
这篇关于如何获得可可中NSArray的前x个元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!