Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ghousemd

macrumors newbie
Original poster
Jun 25, 2011
21
0
HI everybody i have an issue and couldn't able to solve it .so,any help from u guys would be really helpfull.issue is

i am having a Mutabledictionary in the format of
Bank
id 2
kd 4
gd 5
gang
id 4
kd 8
gd 1
like this and another dictionary in the format of
Bank gd
gang kd
like that i need to comare this dictionary with the above one and retrieve their corresponding values .i have tried this code but it is giving error
Code:
int count = [mFavoritesArray count];
for (NSMutableDictionary *dd in mTest) {
for (int i=0; i < count; i++) {
NSMutableDictionary *tmp = [dd valueForKey:[mFavoritesArray objectAtIndex:i]];
error is NSUnknownKeyException', reason: valueForUndefinedKey this class is not key value coding-compliant for the key kd.
 
Last edited by a moderator:
valueForKey: is part of KVC system. You should not be using that for this purpose. You should be using objectForKey:.

i have used that one also but it is showing error
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFString objectForKey:]: unrecognized selector sent to instance
 
i have used that one also but it is showing error
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFString objectForKey:]: unrecognized selector sent to instance

Then you have a memory management problem as you are sending the message to a string, not a dictionary.
 
Then you have a memory management problem as you are sending the message to a string, not a dictionary.

yes u r right when i print dd dictionary it is having a single elment only .so could u tell me how to implement for each loop with dd dictionary and where i am doing wrong
 
What is mTest?


is a Dictionary

and another issue is
hi guys i am trying to read plist which is inthe form of
Bug dictionary
key value
key value
hint dictionary
z value
d value
like this when i tried to read it using NSMutable dictionary it is reading properly but when i tried to read it using NSArray it is not reading the contents and code i am using are

NSString *mm=[[NSBundle mainBundle] pathForResource:mad:"Score" ofType:mad:"plist"];
NSArray *mTest=[[NSArray alloc] initWithContentsOfFile:mm];// here it is not working

NSString *mm=[[NSBundle mainBundle] pathForResource:mad:"Score" ofType:mad:"plist"];
NSMutable dictionary *mTest=[[NSMutableDictionary alloc] initWithContentsOfFile:mm];// here it is working
the reason why i am trying to use NSarray is in apple periodic elements example it is working but it is not working in my code
any suggestion are welcome
 
So what does iteration over a dictionary do? Hint it doesn't iterate over the values alone.

Bank dictionary
id 2
kd 4
gd 5
gang dictionary
id 4
kd 8
gd 1
like this and another dictionary in the format of
Bank gd
gang kd

i need to compare these two dictionaries and add all values
the code i am using is and for adding i dont know how to that any code from you will be a great helpfull to me



NSString *mm=[[NSBundle mainBundle] pathForResource:mad:"Score" ofType:mad:"plist"];
NSMutableDictionary *mTest=[[NSMutableDictionary alloc] initWithContentsOfFile:mm];
NSArray *aa=[mTest mutableCopy];
for (NSDictionary *dd in aa)// here dd is not able to retrieve data
{
for (int i=0; i < count; i++) {

NSMutableDictionary *tmp = [dd valueForKey:[mFavoritesArray objectAtIndex:i]];
}
}
 
Last edited:
i need to get the sum of all values

So if you want the values what options do you have? Can you get an array of values from a dictionary? What does the documentation have to say on this.

Honestly I feel like I am having to excessively spoon feed you answers. The ability to read and understand the documentation is a core programming skill that I suggest you need to work on.
 
So if you want the values what options do you have? Can you get an array of values from a dictionary? What does the documentation have to say on this.



Bank dictionary
id 2
kd 4
gd 5
gang dictionary
id 4
kd 8
gd 1
like this and another dictionary in the format of
Bank gd
gang kd


getting all values and adding i know about it but here i need to extract only values which are in second dictionary and need to add it for example in second dictionary i am having gd and kd i need to use that and get there corresponding values and add it which i dont know
 
You ignored my question completely. I am not going to continue this. Look at the documentation for a method that will return an array of values from a dictionary. You seem to expect someone else to write your code for you. That is not programming. It's just utter laziness.
 
Code:
for (NSDictionary *dd in aa)// here dd is not able to retrieve data
{
       for (int i=0; i < count; i++) {
           
       NSMutableDictionary *tmp = [dd valueForKey:[mFavoritesArray objectAtIndex:i]];
}

Robbieduncan, what do you think "for (NSDictionary *dd in aa)" is doing?

You said mTest is an NSMutableDictionary. So, for each dd, NSMutableDictionary, in mTest you want the following code inside the loop to execute? Does mTest contain NSMutableDictionaries? Is it unable to retrieve data or is it trying to retrieve the wrong type of data you are looking for?
 
Code:
for (NSDictionary *dd in aa)// here dd is not able to retrieve data
{
       for (int i=0; i < count; i++) {
           
       NSMutableDictionary *tmp = [dd valueForKey:[mFavoritesArray objectAtIndex:i]];
}

what do you think "for (NSDictionary *dd in aa)" is doing?

You said mTest is an NSMutableDictionary. So, for each dd, NSMutableDictionary, in mTest you want the following code inside the loop to execute? Does mTest contain NSMutableDictionaries? Is it unable to retrieve data or is it trying to retrieve the wrong type of data you are looking for?


mTest contain NSMutabaleDictionaries and it is retrieveing data and dd it should retrieve each dictionary from it but it is not working

i found solution for my problem code is


for (id key in mTest)
{
NSLog(@"%@",key);
id value = [mTest objectForKey:key];
id vv=[mFinalDictionary valueForKey:key];
id gg=[value valueForKey:vv];
NSLog(@"%@",value);
NSLog(@"%@",vv);
NSLog(@"%@",gg);
}

----------



----------

You ignored my question completely. I am not going to continue this. Look at the documentation for a method that will return an array of values from a dictionary. You seem to expect someone else to write your code for you. That is not programming. It's just utter laziness.

sorry for disturbing u anyhow thanks for ur replay
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.