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

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -