Im trying to convert a NSString to an int, and then back again after having added one to it:
So instead of getting 1 as a result after first run, Im left with a whopping 57840 instead!? I simply have no idea what to make of that, except perhaps that it might be the numerical value of "NULL"? Still, if thats the case then the value is set to 0 and this wouldnt be an issue.
Any ideas?
Code:
// Get string from settings
NSString *str_Right_Answers = [[NSUserDefaults standardUserDefaults] stringForKey:@"settings_Right_Answers"];
// If not initialized, set it to 0
if (str_Right_Answers == NULL) { str_Right_Answers = @"0"; }
// DEBUG: shows inital value to be NULL (and is thus set to "0"), as this setting is not initialized anywhere else.
// Convert string to int
int n_Right_Answers = (int)str_Right_Answers;
// Increase and convert int to string
str_Right_Answers = [NSString stringWithFormat: @"%d", (n_Right_Answers + 1)];
// DEBUG: Expected value should be 1 (first run) but comes up as 57840 instead.
So instead of getting 1 as a result after first run, Im left with a whopping 57840 instead!? I simply have no idea what to make of that, except perhaps that it might be the numerical value of "NULL"? Still, if thats the case then the value is set to 0 and this wouldnt be an issue.
Any ideas?