I'm missing something here, and feeling like an idiot about it.
I'm using a UIPickerView in my app, and I need to assign the row number to a 32-bit integer attribute for a Core Data object. To do this, I am using this method:
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
object.integerAttribute = row;
}
This is giving me a warning:
warning: passing argument 1 of 'setIntegerAttribute:' makes pointer from integer without a cast
What am I mixing up here?
--Edit 1--
Ok, so I can get rid of the warning by changing the method to do the following:
NSNumber *number = [NSNumber numberWithInteger:row];
object.integerAttribute = number;
However, I still get a value of 0
for object.integerAttribute
if I use NSLog
to print it out. object.integerAttribute
has a max value of 5, so I print out number
instead, and then I'm getting a number above 62,000,000. Which doesn't seem right to me, since there are 5 rows. If I NSLog
the row
variable, I get a number between 0 and 5. So why do I end up with a completely different number after casting the number to NSNumber
?
--Edit 2--
Ok, so I'm realizing that there is some fundamental idea that I don't understand. I now understand that the 60 million + number can be cast back to the correct 0-5 number by using integerValue
. So, it seems my question is how can I save an integer between 0-5 to the attribute if the NSNumber
that is returned is over 60 million? Do I need to be using a different data type?
--Edit 3--
I have removed the min / max / and default values for the attribute, but still no success. If I NSLog
the number
value, I get 61 million +. If I NSLog
the integerValue
of the number
value, I get the correct 0 - 5 value. So it must not be what I thought it was (hitting the max number and not being a valid value for the attribute). Here is the NSLog
call I am making:
NSLog(@"Attribute being assigned value of: %@", [NSString stringWithFormat:@"%d", object.integerAttribute]);
I have also used the following, but still get the 0
value:
NSLog(@"Attribute being assigned value of: %@", [NSString stringWithFormat:@"%d", [object.integerAttribute integerValue]]);
Can't believe I am having such a hard time with this...
--Edit 4--
According to the debugger, the number
variable is never even receiving a value. It gets set as nil
, and passes that on to object.integerAttribute
.
--Edit 5--
I was wrong in my above statement. The value being passed to number
is not nil
. It's being passed the value (according to the debugger) <value
.
--Final edit--
sigh
I am a dummy. I had a typo sending passing the object to the class handling this method. I'll mark my answer as accepted as soon as I can.