目标c组数组 [英] objective c group array

查看:60
本文介绍了目标c组数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的数组:

{
    toNumber = +79995840405;
    type = 9;
}
{
    toNumber = +79995840405;
    type = 65;
}
{
    toNumber = +79995840405;
    type = 9;
}
{
    toNumber = +79995840405;
    type = 65;
}

如何将项目按toNumber&类型?谢谢

How can I group items by toNumber & type? thanks

推荐答案

您提供的详细信息很少,这使人们很难为您提供帮助;并且没有显示您尝试过的内容并解释了您遇到的困难,这就是SO方法-此处的人员会为您提供帮助,而不是为您完成工作.

You have provided little detail, which makes it hard for people to help you; and haven't shown what you have tried yourself and explained where you got stuck, which is the SO approach - people here will help you, not do the work for you.

以上就是为什么您获得接近票数的原因.

The above is why you are getting close votes.

这就是说,让我们看看是否可以为您指明正确的方向,但这是基于对您所拥有和所遇到问题的猜测.

That said let's see if we can point you in the right direction, but understand this is based on guesswork about what you have and your problem.

因此,听起来好像您有一个字典(NSDictionary)的数组(NSArray),并希望生成一个数组字典.一个简单的迭代可以用于此:

So it sounds like you have an array (NSArray) of dictionaries (NSDictionary) and wish to produce a dictionary of arrays. A straightforward iteration can be used for that:

  1. 创建一个空结果字典(NSMutableDictionary)
  2. 遍历数组,查看每个元素(foreach)
  3. 使用元素的type值作为结果字典的键值:

  1. Create an empty result dictionary (NSMutableDictionary)
  2. Iterate over your array looking at each element (foreach)
  3. Using the type value of your element as the key value of your result dictionary:

3.1.如果结果字典中没有该键的条目,请创建一个新数组(NSMutableArray),向其中添加元素的toNumber值,然后将该数组添加至结果字典中.

3.1. If there is no entry in your result dictionary for the key create a new array (NSMutableArray), add the element's toNumber value to it, and add the array to your result dictionary.

3.2否则,只需将toNumber值添加到结果字典的键条目处的现有数组即可.

3.2 Otherwise simply add to toNumber value to the existing array at the key entry of your result dictionary.

就是这样,每个项目符号都是一两行代码.

That's it, each bullet is a line or two of code.

如果您遇到新问题,请提供详细信息,显示代码并解释问题所在.毫无疑问,有人会从那里帮助您.

If you get stuck as a new question, providing details, showing your code, and explaining what you problem is. Someone will undoubtedly help you from there.

HTH

这篇关于目标c组数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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