objective c - Should I use NSNumber instead of basic C number types? -
what benefit of using nsnumber foundation framework instead of basic c types (int, float, double)?
using nsnumber:
nsnumber *intnumber; nsinteger myint; intnumber = [nsnumber numberwithinteger: 100]; myint = [intnumber integervalue];
using pure c:
int intnumber; intnumber = 100;
seems lot easier , economic use c.
i know nsnumber object (or class?) type, why use them instead simple c variables? when should use them?
the purpose of nsnumber
box primitive types in objects (pointer types), can use them in situations require pointer-type values work.
one common example: have use nsnumber
if want persist numeric values in core data entities.
you can , should use primitives calculations (unless decimals, in case use nsdecimal
or nsdecimalnumber
).
Comments
Post a Comment