-3

I'm trying to store data in NSMutableDictionary. continue change NSString value I want to store this value in NSMutableDictionary, but when second time store value in NSMutableDictionary then clear old value so how to store one by one value in NSMutableDictionary.

    NSString *tempitemname = itemselectedlbl.text;
    NSString *temprate = ratelbl.text;
    NSString *tempquant = quantitylbl.text;
    NSString *temptotal = totallbl.text;
    NSString *temptotalbill = totalbilllbl.text;

    dict = [[NSMutableDictionary alloc]init];

    [dict setValue:tempitemname forKey:@"itemname"];
    [dict setValue:temprate forKey:@"rate"];
    [dict setValue:tempquant forKey:@"quantity"];
    [dict setValue:temptotal forKey:@"total"];
    [dict setValue:temptotalbill forKey:@"totalbill"];

Continue change all labels value I want store these values in NSMutableDictionary.

reVerse
  • 35,075
  • 22
  • 89
  • 84
  • 1
    Of course they clear the old value - an `NSDictionary` - any dictionary/hash/object is a key-value mapping - one key to one value. What do you want to accomplish? Maybe you want to store an `NSMutableArray` of strings for each key? – Adam Jenkins Nov 15 '14 at 10:28
  • 2
    Please check the stack overflow for similar questions before you ask anything. These are very basic questions and a lot of questions and answers are already available regarding this. – Rameswar Prasad Nov 15 '14 at 10:36
  • Sorry to say this but don't ask such type of questions. First search about the question you will get hundreds of answers related to your questions. – Gaurav Gilani Nov 15 '14 at 10:53

1 Answers1

0

NSDictionary/NSMutableDictionary doesn't allow duplicate key to store inside them. So when you set the values second time then it overwrites the data if there is already a key available inside the dictionary. So you can't store again and again and still expect it to hold all the data.

Rameswar Prasad
  • 1,331
  • 17
  • 35