ios - Create a new plist from the existing plist? -
i have plist in below first image ,thats main plist , in field "bid" unique . have value of bid (for example bid=90) need search value in entries of main (first image)plist and create new plist& retrieve corresponding values(bid,description,category,rating) belongs plist .how can this?
edit
if have multiple values me bid =88 , bid=90 i have create new plist main plist (as shown in first image) result should image 3
nsstring *path = [[nsbundle mainbundle] pathforresource:@"mainplistfile" oftype:@"plist"]; //path has path main plist. nsdictionary *dictionary=[nsdictionary dictionarywithcontentoffile: path]; nsarray *listbook = [dictionary objectforkey:@"listbook"]; (nsdictionary *item in listbook) { if ([[item objectforkey:@"bid"] isequaltostring yournsstringwithbidtosearch]) { //now item desired dictionary, can values using objectforkey //or write file below. [item writetofile:pathtosavenewplist automatically:no]; break; } }
remember have first create nsstring pathtosavenewplist , yournsstringwithbidtosearch, i'll leave you.
so edited question : lets assume have nsarray bidstosearch has nsstrings of bid values searched :
nsmutablearray *targetlistbook = [[nsmutablearrray alloc] init]]; nsdictionary *dictionary=[nsdictionary dictionarywithcontentoffile:[[nsbundle mainbundle] pathforresource:@"mainplistfile" oftype:@"plist"]]; (nsdictionary *item in [dictionary objectforkey:@"listbook"]) if ([bidstosearch containsobject:[item objectforkey:@"bid"]]) [targetlistbook addobject:item]; [@{listbook:targetlistbook} writetofile:pathtosavenewplist automatically:no];
Comments
Post a Comment