views:

385

answers:

2

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.

+1  A: 

I think you need to be expecting to get back an nsnumber. Even though in your managedobjectmodel you put in the value as an int, if you look at the class definition that is generated the property will be listed as an nsnumber. Just unpack and pack up the nsnumber as needed. Maybe the 62. Million thing comes from printing out an object as opposed to value? Show me you log calls.

nickthedude
Yeah, that's what I figured. But no matter what I do, I get zero back from the `object.integerValue` attribute. I have edited the question to update the problem, complete and I have added my `NSLog` call.
Gordon Fontenot
Also, I changed my variable in the example from `object.integerValue` to `object.integerAttribute` to be ( a little) less confusing.
Gordon Fontenot
try %i instead of %d as your log placeholder. also use the xcode debugger to step through and you can see the variables by using the screen in the upper right.
nickthedude
Using `%i` doesn't fix anything. It's not even passing anything to the `number` variable. That is coming back as `nil` according to the debugger.
Gordon Fontenot
try dis: NSLog(@"Attribute being assigned value of: %i",[object.integerAttribute intValue]); also another good trick is to right click on the variable in question in the upper right list of the xcode debugger and click print description to console.
nickthedude
When I print the description to console, I get 2 lines. Both read `A syntax error in expression, near 'value)'.`
Gordon Fontenot
+2  A: 

I think you're an idiot and can't type right. Check for typos.

Gordon Fontenot
Haha. What was the typo?
MrHen
When I was sending the value for the `object` I was sending it to the wrong class. So the class that was handling these functions actually didn't have an `object` instantiated.Really dumb of me.
Gordon Fontenot