objective c group array

前端 未结 1 1816
北恋
北恋 2021-01-29 14:15

I have array like this:

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


        
相关标签:
1条回答
  • 2021-01-29 14:41

    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.

    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. 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. 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 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

    0 讨论(0)
提交回复
热议问题