Merge dictionary array dict

Source: Internet
Author: User

//
// Viewcontroller. m
// H
//
// Created by Jason on 13-3-1.
// Copyright (c) 2013 hufeng. All rights reserved.
//

# Import "viewcontroller. H"

@ Interface viewcontroller ()

@ End

@ Implementation viewcontroller
Typedef struct
{
Bool ishaskey;
Int position;
} Returndate;

-(Void) viewdidload
{
[Super viewdidload];
// Do any additional setup after loading the view, typically from a nib.

Nsdictionary * dict = @{
@ "Pushinfo ":@[
@{
@ "Content": @ "handling instructions ",
@ "Infoid": @ "info001 ",
@ "Modetype": @ "DB ",
@ "Systemtype": @ "OA"
},
@{
@ "Content": @ "handling instructions ",
@ "Infoid": @ "info002 ",
@ "Modetype": @ "St ",
@ "Systemtype": @ "OA"
},
@{
@ "Content": @ "handling instructions ",
@ "Infoid": @ "info003 ",
@ "Modetype": @ "ls ",
@ "Systemtype": @ "OA"
},
@{
@ "Content": @ "handling instructions ",
@ "Infoid": @ "info004 ",
@ "Modetype": @ "Ed ",
@ "Systemtype": @ "OA"
},
@{
@ "Content": @ "handling instructions ",
@ "Infoid": @ "info002 ",
@ "Modetype": @ "SD ",
@ "Systemtype": @ "OA"
},
@{
@ "Content": @ "handling instructions ",
@ "Infoid": @ "info005 ",
@ "Modetype": @ "SD ",
@ "Systemtype": @ "OA"
},
@{
@ "Content": @ "handling instructions ",
@ "Infoid": @ "info005 ",
@ "Modetype": @ "sddd ",
@ "Systemtype": @ "OA"
},
@{
@ "Content": @ "handling instructions ",
@ "Infoid": @ "info006 ",
@ "Modetype": @ "sddd ",
@ "Systemtype": @ "OA"
},
]
};
// Nslog (@ "The dict =%@", dict );

Nsarray * array = [dict objectforkey: @ "pushinfo"];
[Self returnkey: array key: @ "info002"];

Nsmutablearray * uniquarray = [nsmutablearray array];
Nsmutablearray * uniquarraytmp = [[array mutablecopy] autorelease];
For (INT I = [uniquarraytmp count]; I> 0; I --)
{
Nsstring * Key = [[uniquarraytmp objectatindex: I-1] objectforkey: @ "infoid"];
Returndate dt = [self returnkey: uniquarray key: Key];
If (Dt. ishaskey)
{
Nsmutabledictionary * dicta =
[[[Uniquarraytmp objectatindex: I-1] mutablecopy] autorelease];
Nsstring * A = [dicta objectforkey: @ "modetype"];
Nsmutabledictionary * dictb =
[[[Uniquarray objectatindex: DT. position] mutablecopy] autorelease];
Nsstring * B = [dictb objectforkey: @ "modetype"];
[Dicta setobject: [nsstring stringwithformat: @ "% @ ^ % @", a, B] forkey: @ "modetype"];
[Uniquarray replaceobjectatindex: DT. Position withobject: dicta];
}
Else
{
[Uniquarray addobject: [uniquarraytmp objectatindex: I-1];
[Uniquarraytmp removeobjectatindex: I-1];
}
}
Nslog (@ "The after \ n % @", uniquarray );
}

-(Returndate) returnkey :( nsarray *) array key :( ID) Key
{
Int I = 0;
Returndate date;
Date. Position = 0;
Date. ishaskey = no;

For (nsdictionary * dict in array)
{
If ([[dict objectforkey: @ "infoid"] isequal: Key]
)
{
Date. ishaskey = yes;
Date. Position = I;
Break;
}
Else
{
I ++;
}
}
Return date;
}

-(Void) didreceivememorywarning
{
[Super didreceivememorywarning];
// Dispose of any resources that can be recreated.
}

@ End

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.