ios 访问 NSArray 的元素及其索引

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19217352/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 02:08:34  来源:igfitidea点击:

acess element of NSArray with its index

iosnsarray

提问by sreejith.virgo

Is it possible to access elements of an NSArraybased on index and use them for comparison/operations?

是否可以访问NSArray基于索引的元素并将它们用于比较/操作?

Just like arrayName[ith element]in C/C++

就像arrayName[ith element]在 C/C++ 中一样

回答by Toseef Khilji

Yes, you can access elements of an NSArray based on index .

是的,您可以根据索引访问 NSArray 的元素。

NSArray *a=@[@"s1",@"s2",@"s3"];
NSLog(@"%@",a[1]);

回答by Jay Gajjar

Try this

尝试这个

arrayName[yourIndex];

or

或者

[arrayName objectAtIndex:yourIndex];

回答by Kiattisak Anoochitarom

You can use 'Index Subscripting Literal' that Apple Provide on iOS 6 SDK later

您可以稍后在 iOS 6 SDK 上使用 Apple 提供的“索引下标文字”

NSArray *array = @[1, 2, 3];
NSLog(@"%@", array[0])

回答by user1673099

Try this way.

试试这个方法。

[arrayname objectAtindex:yourIndex]

[arrayname objectAtindex:yourIndex]