通过循环 NSMutableArray 检索整数
有人可以告诉我如何通过循环 NSMutableArray 来检索值吗?我的代码基本上将整数添加到数组中,如下所示:
NSMutableArray *ptr = [[NSMutableArray alloc] init];
[ptr addObject:[NSNumber numberWithInt:1]];
[ptr addObject:[NSNumber numberWithInt:2]];
[ptr addObject:[NSNumber numberWithInt:3]];
// How to retrieve them as integers?
我试图从数组中检索每个数字并将它们加起来为一个总值。
Can someone show me how to retrieve values by looping through a NSMutableArray
? My code, which basically adds integer numbers to the array, is below :
NSMutableArray *ptr = [[NSMutableArray alloc] init];
[ptr addObject:[NSNumber numberWithInt:1]];
[ptr addObject:[NSNumber numberWithInt:2]];
[ptr addObject:[NSNumber numberWithInt:3]];
// How to retrieve them as integers?
I'm trying to retrieve each number from the array and sum them up to a total value.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它实际上非常简单:
Its actually pretty simple:
我也是新手,所以我的答案可能是错误的,但试试这个:
I'm also a newbie so my answer may be wrong, but try this: