Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inserting an integerValue into a dictionary

I want to get some value from a textfield and convert into a integer.

NSMutableDictionary* dic = [[NSMutableDictionary alloc]init];
[dic setValue:txtTable.text forKey:@"Table"];

I tried to use this but it doesn't work:

[dic setValue:[txtTable.text integerValue] forKey:@"Table"];

Thanks for help...

like image 843
Gustavo Barbosa Avatar asked Dec 04 '25 12:12

Gustavo Barbosa


2 Answers

NSInteger intVal = [txtTable.text integerValue];
dict[@"Table"] = @(intVal);
like image 50
diederikh Avatar answered Dec 06 '25 05:12

diederikh


You need to wrap the integer value in an NSNumber value.

NSInteger val = [txtTable.text integerValue];
NSNumber *num = [NSNumber numberWithInteger:val];
[dic setObject:num forKey:@"Table"];
like image 24
rmaddy Avatar answered Dec 06 '25 06:12

rmaddy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!