简体   繁体   English

如何使用另一个NSArray的最后30个对象创建一个新的NSArray?

[英]How to create a new NSArray with the last 30 objects from another NSArray?

I have a NSArray with 493 objects and need to create a new one with just the last 30 objects from the first array. 我有一个包含493个对象的NSArray,需要使用第一个数组中的最后30个对象创建一个新对象。

I know how to create a new array with the first 10 or 30 etc, but the other way around I can't. 我知道如何使用前10或30等创建一个新数组,但反过来我不能。

I tried using this code: 我尝试使用此代码:

NSArray *tempArray = [qtdPrecos subarrayWithRange:NSMakeRange([qtdPrecos count]-30, [qtdPrecos count]-1)];

But I got this error: 但我得到了这个错误:

[NSArray subarrayWithRange:]: range {463, 492} extends beyond bounds [0 .. 492]'

So any one could help??? 所以任何人都可以帮忙??? Thanks!!! 谢谢!!!

NSRange结构的第二部分是长度

在NSMakeRange中,第一个参数是开始,但第二个参数是范围的长度

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM