Require Integer Value not Memory Address whilst avoiding Invalid receiver type compiler warning

Posted by Dave Anderson on Stack Overflow See other posts from Stack Overflow or by Dave Anderson
Published on 2011-01-06T05:46:59Z Indexed on 2011/01/06 5:54 UTC
Read the original article Hit count: 254

I have the following code;

int days = [[SettingsUtils daysToRetainHistory] intValue];
[retainHistory setText:[NSString stringWithFormat:@"Days to retain History: %d", days]];
[daysToRetainHistory setValue:days animated:NO];

where [SettingsUtils daysToRetainHistory] is as follows;

+ (int) daysToRetainHistory {
    return (int)[[NSUserDefaults standardUserDefaults] objectForKey:@"CaseBaseDaysToRetainHistory"];
}

I get the compiler warning Invalid receiver type 'int' because I call intValue on an int but unless I do this I can't seem to get the integer value out and always end up with the memory address i.e. 98765432 instead of 9 which ruins the UILabel display [retainHistory] and the UISlider [daysToRetainHistory] value.

How do I avoid the compiler warning and still get my integer value in the label and the necessary float value for setting the UISlider value?

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about int