如何搜索NSMutableArray [英] How to search through a NSMutableArray

查看:42
本文介绍了如何搜索NSMutableArray的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个NSMutableArray,我需要搜索一个字符串并在找到该字符串的数组中返回键.因此,例如,如果我搜索"ipod"并且它是数组中的第4个,它将返回3或字符串所处的任何位置.什么是最好的方法?

I have a NSMutableArray that I need to search for a string and return the key in the array where the string was found. So for example if I'm searching "ipod" and it's the 4th in the array, it would return 3 or whatever position the string is in. What's the best way to do this?

推荐答案

return [theArray indexOfObject:@"ipod"];

参考:请注意,NSMutableArray继承自NSArray,因此任何NSArray方法也可以在NSMutableArray上使用.

Note that NSMutableArray inherits from NSArray, so any NSArray methods can be used on NSMutableArray too.

这篇关于如何搜索NSMutableArray的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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