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
Code:
for (id key in mTest)//mTest is a NSMutableDictionary
{
int result1=0;
NSMutableArray *myArray=[[NSMutableArray alloc]init];

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

NSInteger value1=[value valueForKey:vv];// VV is a NSNumber
[myArray addObject:[NSNumber numberWithInt:value1]];// array is storing garbage values


result1 +=result1+value1;// here result is not getting added
NSLog(@"%@",value);
NSLog(@"%@",vv);
NSLog(@"%@",value1);
NSLog(@"%@",result1);
NSLog(@"%@",myArray);

}
here i need to add all NSNumbers values for that i am using array to store all values and second option i am using is directly i am trying to add using result operation . any suggestions are welcome
 
What does the IDE (XCode) have to do with anything? Anyway you are declaring result1 within the for loop scope. That is almost certainly wrong as a new result1 will be created each time round the loop and initialised to 0. This is a very fundamental error. If you don't mind me asking how much programming training and experience do you have? Do you understand the C rules of variable scope?
 
NSInteger is not the same as NSNumber, nor is it a subclass of NSNumber. If you want an NSInteger from an NSNumber sent integerValue to the NSNumber object.

At the moment, value1 won't contain the number. It will contain the pointer to the NSNumber object returned from valueForKey:. That's the "garbage" values you're seeing in myArray.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.