I am attempting to perform basic NSDecimal math such as addition multiplication and subtraction of NSDecimals. Is this possible to accomplish? trying to use NSDecimalAdd getting error
NSDecimal' to parameter of incompatible type 'NSDecimal * _Nonnull'
_meat.colonyQueenObject.count.creatureCount = [colonyQueenNumber decimalValue];
-(void)adjustCountsCreatureCountforAddedCreatures:(NSDecimal)creaturesAdded meatCount:(NSDecimal)meatCount larvaCount:(NSDecimal)larvaCount creatureType: (int)creatureType{
NSDecimalAdd(_meat.colonyQueenObject.count.creatureCount, _meat.colonyQueenObject.count.creatureCount, &creaturesAdded, NSRoundBankers);
}
NSDecimalAdd(&_meat.colonyQueenObject.count.creatureCount, &_meat.colonyObject.count.creatureCount, &creaturesAdded, NSRoundBankers);
also fails
NSDecimal
is a value type; just likeint
,float
, etc. However the math functions, such asNSDecimalAdd
, take their arguments and return their result by address - that is the arguments & result must be variables passed by address, obtained using the&
operator, to the function and not by value.Your second attempt:
is the closest to being correct, but the first two arguments are incorrect as you are attempting to pass the address of a property - which is not possible. So you should be seeing an error like:
If you wish to use properties you will have to use temporary intermediate local variables to hold your values. E.g. something along the lines of:
You should also be checking the return value of
NSDecimalAdd
as it indicates whether the operation was performed correctly (NSCalculationNoError
).HTH