0

Hi i have two Arrays one being Parsed Data that has multiple entries at each cell (FolderName & ID) i want this data to be saved into another array like it is stored in the first array

   FilteredData = [[NSMutableArray alloc]initWithArray:[ParsedData ValueForKey:@"FolderName"]];

   SearchData = [[NSMutableArray alloc]initWithArray:FilteredData];

This is what i have been trying, The data Containing a dictionary at each entry is ParsedData, And the Array in which i have to copy these items is SearchData.

The Array (Parsed Data) Containing the dictionary looks like this

 PARSED DATA (
    {
    CreatedBy = 1;
    FolderName = Posteingang;
    ID = 13000;
    ParentID = 0;
},
    {
    CreatedBy = 1;
    FolderName = Freigaben;
    ID = 13001;
    ParentID = 0;
},

From this Array I need to Get the FolderName And the ID and get them in the SearchData Array

SearchData (
    Posteingang;
    13000;     
    Freigaben;
    13001;
)

I hope the question is clear now

enter image description here

18
  • 2
    so what is the problem? Commented May 1, 2013 at 9:07
  • this is just copying the foldername to the array whereas i need the ID as well Commented May 1, 2013 at 9:15
  • An array can contain one value either folderName or ID. If you need both the values you need nested array or dictionary or even a custom class. In worst use stringWithFormat and append both of them. now tell what you want ? Commented May 1, 2013 at 9:17
  • I want a dictionary inside an array which contains foldername and id Commented May 1, 2013 at 9:21
  • Question was not clear? Commented May 1, 2013 at 9:23

3 Answers 3

1

check this one,

NSMutableArray *searchData = [NSMutableArray new];
    for(NSDictionary *dict in ParsedDataArray){//here ParsedDataArray  means PARSED DATA array name
        NSDictionary *tempDict=[[NSDictionary alloc]initWithObjectsAndKeys:[dict ValueForKey:@"FolderName"],@"FolderName",[dict ValueForKey:@"ID"],@"ID" nil], 

        [searchData addObject:dict];
    }
Sign up to request clarification or add additional context in comments.

1 Comment

@RANA:check this one may be it'l helps you.
1

It seems like you misspelled the method name, it should be:

dictionaryWithObjectsAndKeys:

Notice the "s" after Object.

Comments

0

I want a dictionary inside an array which contains foldername and id

So you can get it using this:

NSMutableArray *searchData = [NSMutableArray new];
for(NSDictionary *dict in parsedDataArray){
    NSDictionary *tempDict=@{@"FolderName":dict[@"FolderName"], 
                             @"ID":dict[@"ID"]};
    [searchData addObject:tempDict];
}

EDIT:

@[@"key:@"object"] is the new dictionary literal.

If you are using Xcode 4.3 or older need to do as:

NSDictionary *tempDict=@{@"FolderName":dict[@"FolderName"], 
                                 @"ID":dict[@"ID"]};

means,

NSDictionary *tempDict=[NSDictionary dictionaryWithObjectsAndKeys:[dict objectForKey:@"FolderName"], @"FolderName",[dict objectForKey:@"ID"],@"ID", nil];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.