Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Aug 24, 2011, 03:58 AM   #1
ghousemd
macrumors newbie
 
Join Date: Jun 2011
Mutable dictionary issue

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 robbieduncan; Aug 24, 2011 at 04:18 AM. Reason: Please use the code tags, thanks
ghousemd is offline   0 Reply With Quote
Old Aug 24, 2011, 04:21 AM   #2
robbieduncan
Demi-God (Moderator)
 
robbieduncan's Avatar
 
Join Date: Jul 2002
Location: London
valueForKey: is part of KVC system. You should not be using that for this purpose. You should be using objectForKey:.
robbieduncan is offline   0 Reply With Quote
Old Aug 24, 2011, 04:31 AM   #3
ghousemd
Thread Starter
macrumors newbie
 
Join Date: Jun 2011
Quote:
Originally Posted by robbieduncan View Post
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
ghousemd is offline   0 Reply With Quote
Old Aug 24, 2011, 04:42 AM   #4
robbieduncan
Demi-God (Moderator)
 
robbieduncan's Avatar
 
Join Date: Jul 2002
Location: London
Quote:
Originally Posted by ghousemd View Post
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.
robbieduncan is offline   0 Reply With Quote
Old Aug 24, 2011, 07:00 AM   #5
ghousemd
Thread Starter
macrumors newbie
 
Join Date: Jun 2011
Quote:
Originally Posted by robbieduncan View Post
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
ghousemd is offline   0 Reply With Quote
Old Aug 24, 2011, 07:57 AM   #6
robbieduncan
Demi-God (Moderator)
 
robbieduncan's Avatar
 
Join Date: Jul 2002
Location: London
What is mTest?
robbieduncan is offline   0 Reply With Quote
Old Aug 25, 2011, 02:11 AM   #7
ghousemd
Thread Starter
macrumors newbie
 
Join Date: Jun 2011
Quote:
Originally Posted by robbieduncan View Post
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:@"Score" ofType:@"plist"];
NSArray *mTest=[[NSArray alloc] initWithContentsOfFile:mm];// here it is not working

NSString *mm=[[NSBundle mainBundle] pathForResource:@"Score" ofType:@"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
ghousemd is offline   0 Reply With Quote
Old Aug 25, 2011, 06:34 AM   #8
robbieduncan
Demi-God (Moderator)
 
robbieduncan's Avatar
 
Join Date: Jul 2002
Location: London
Quote:
Originally Posted by ghousemd View Post
is a Dictionary
So what does iteration over a dictionary do? Hint it doesn't iterate over the values alone.
robbieduncan is offline   0 Reply With Quote
Old Aug 25, 2011, 06:57 AM   #9
ghousemd
Thread Starter
macrumors newbie
 
Join Date: Jun 2011
Quote:
Originally Posted by robbieduncan View Post
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:@"Score" ofType:@"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 by ghousemd; Aug 25, 2011 at 07:04 AM.
ghousemd is offline   0 Reply With Quote
Old Aug 25, 2011, 07:04 AM   #10
robbieduncan
Demi-God (Moderator)
 
robbieduncan's Avatar
 
Join Date: Jul 2002
Location: London
Quote:
Originally Posted by ghousemd View Post
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.
robbieduncan is offline   0 Reply With Quote
Old Aug 25, 2011, 07:13 AM   #11
ghousemd
Thread Starter
macrumors newbie
 
Join Date: Jun 2011
[QUOTE=robbieduncan;13242891]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
ghousemd is offline   0 Reply With Quote
Old Aug 25, 2011, 07:16 AM   #12
robbieduncan
Demi-God (Moderator)
 
robbieduncan's Avatar
 
Join Date: Jul 2002
Location: London
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.
robbieduncan is offline   1 Reply With Quote
Old Aug 25, 2011, 04:20 PM   #13
agwilson
macrumors newbie
 
Join Date: Feb 2008
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?
agwilson is offline   0 Reply With Quote
Old Aug 26, 2011, 01:16 AM   #14
ghousemd
Thread Starter
macrumors newbie
 
Join Date: Jun 2011
Quote:
Originally Posted by agwilson View Post
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);
}

----------



----------

Quote:
Originally Posted by robbieduncan View Post
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
ghousemd is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Tags
xcode

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
Adding a dictionary to Dictionary app Sarsay Mac Applications and Mac App Store 2 Oct 23, 2012 03:18 PM
Is Bento 4 a good database software for making a dictionary? MJNBGA Mac Applications and Mac App Store 3 Aug 1, 2012 11:14 PM
[UPDATE] New Oxford American Dictionary 2.0 missing "The Right Word section." IntelliUser iPhone and iPod touch Apps 2 Nov 15, 2010 01:33 PM
ms office 2008 on mac dictionary issue guust Mac Applications and Mac App Store 0 Sep 9, 2010 10:07 AM
Microsoft Word For Mac 08 Dictionary Issue kluckste Mac Applications and Mac App Store 0 Nov 2, 2009 07:18 PM


All times are GMT -5. The time now is 01:23 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

Privacy / DMCA contact / Affiliate and FTC Disclosure
Copyright 2002-2013, MacRumors.com, LLC