i am developing an app where a user adds medicine name and number of times he should take it .. (the add view is presented as modal view).
when i NSlog the values populated from the user it seems to be okay when i try insert them to a dictionary the app crashes
NSString *name = [NSString stringWithString:[MedName_Field text]];
int times = [[times_Field text] intValue];
NSLog(@"%@ - %i",name,times); // <- Here it is OK.
//create a dictionary
NSDictionary *dic = [[NSDictionary alloc] init];
[dic setValue:name forKey:@"Name"]; // <- Crash!
Thanks.
NSDictionaryinstances are immutable so you can’t add/remove anything after they are created. You need to use mutable variant – NSMutableDictionary instead: