从NSMutableArray获取最后五个值 [英] Fetch last five values from NSMutableArray

查看:698
本文介绍了从NSMutableArray获取最后五个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 NSMutableArray ,其计数为10,我想提取最后5个值,并将它们存储在另一个数组中。 我认为 - (NSArray *)subarrayWithRange:(NSRange)范围

  NSRange theRange; 
theRange.location = [wholeArray count] - 5;
theRange.length = 5;
NSArray * result = [wholeArray subarrayWithRange:theRange];

EDIT :小心检查您的数组是否至少有五个元素,否则 subarrayWithRange 会抛出异常。


I have a NSMutableArray whose count is 10 and I want to extract the last 5 values and store them in another array. How can I do this?

解决方案

I think that - (NSArray *) subarrayWithRange:(NSRange)range (doc) might help you.

NSRange theRange;
theRange.location = [wholeArray count] - 5;
theRange.length = 5;
NSArray *result = [wholeArray subarrayWithRange:theRange];

EDIT : Be careful to check that your array has at least five elements, else, subarrayWithRange will throw an exception.

这篇关于从NSMutableArray获取最后五个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆