Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat is the right choice between NSDecimal, NSDecimalNumber, CFNumber?
    text
    copied!<p>I've read a lot about NSDecimal, NSNumber, NSNumberDecimal, CFNumber... and it begins to be a kind of jungle to me.</p> <p>Basically, I'm trying to create a simple model class that will handle simple computations, like this one:</p> <pre><code>#import &lt;Foundation/Foundation.h&gt; @interface Test : NSObject { float rate; float amount; int duration; } - (float)capitalizedAmount; @end @implementation Test - (float)capitalizedAmount { return (amount*pow((1.0+rate),duration)); } @end </code></pre> <p>I want to access these methods and setters with their names as strings, since I plan to have a lot of other classes like this one, and I am only keeping a list of field to do key value coding.</p> <pre><code>// This is just the desired behavior // This evidently won't work with the previous class definition Test *obj = [[Test alloc] init]; [NSNumber numberWithInt:10] ... float r; r = [obj performSelector:NSSelectorFromString(@"capitalizedAmount")]; </code></pre> <p>I understand that this is not possible, that <code>performSelector:</code> will return an object, and thus that <code>capitalizedAmount</code> should return an object. I've read things about <code>NSInvocation</code> and the relevant part in the Objective-C Faq on comp.lang.</p> <p>I also understand that I should use <code>NSDecimalNumber</code>, but there is two things that I would like to know:</p> <ol> <li>Are the memory overhead and performance loss acceptable for a somewhat more complicated class (only financial computations of this kind, showed in an UITableView)? I do not have much background in C...</li> <li>Isn't it too fastidious and complicated to use functions like <code>decimalNumberByAdding:</code>? With Python it was easy to define <code>__add__</code> to use operators with objects. Should I get float values from <code>NSDecimalNumber</code>, then do the computations and returns the result wrapped in an <code>NSDecimalNumber</code>? How would you deal with this problem?</li> </ol> <p>I am looking for a simple and beautiful solution!</p> <p>Just another question in the same area: is <code>CFBoolean</code> the object wrapper for <code>BOOL</code> on iPhone Core Foundation?</p> <p>Thank you very much for your help!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload