Search code examples
iphoneuislider

iPhone UISlider to NSNumber


I'm trying to get the value of a UISlider and store it into part of a CoreData entity.

The score I need to save will either be the value of the slider (i.e. slider.value) or 10 minus the value of the slider (i.e. 10 - slider.value)

I'm trying to put it into an NSNumber and when I use the intValue it works fine.

When I use either...

score = [NSNumber numberWithInt:slider.value];

or...

score = [NSNumber numberWithInt:10 - slider.value];

it works perfectly and I can recall the values at a later date with no problems.

However, I really need to get the value to 1 decimal place but whenever I try this I just can't get it to work.

I really don't even know where to start. I can NSLog the doubleValue out with no problems but I can't figure out how to get this into an NSNumber.

I seem to always get the error "Cannot convert to a pointer type (2)"

Any help is much appreciated.

Thanks


Solution

  • Have you tried numberWithFloat:? If you're using an int, you will of course never get any decimal places because an integer by definition is a whole number.