Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Increment the value of a core-data model field

I'm increasing the amount of a model field using the following code:

- (IBAction) counterButton: (id) sender {
    [model.amount++ stringValue];
}

It was working fine until I upgraded Xcode. Since then I've been getting the following error:

"Arithmetic on pointer to Interface 'NSNumber'. which is not a constant size in non-fragile ABI"

When the code was working it incremented the value by 1 each time a UIButton was touched.

any help would be greatly appreciated. thanks

like image 245
hanumanDev Avatar asked Nov 11 '11 10:11

hanumanDev


2 Answers

You cant perform ++ on a NSNumber which in an object not a primitive type. Also it is an unmutable type.

If you want increase the value of amount you can try this:

- (IBAction) counterButton: (id) sender {
    NSInteger amount =[model.amount integerValue];
    amount++;
    model.amount = [NSNumber numberWithInteger:amount];

}
like image 119
rckoenes Avatar answered Oct 16 '22 00:10

rckoenes


Unless model.amount used to be an NSInteger I don't see how that would ever have worked. The ++ operator doesn't work on NSNumbers. Or at least, it doesn't increment the value that's stored in it -- instead it would increment the pointer to the object, which isn't what you want.

Instead you need to increment the value "long hand."

like image 27
Stephen Darlington Avatar answered Oct 16 '22 01:10

Stephen Darlington