Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

sam256

macrumors newbie
Original poster
Oct 4, 2011
4
0
What is the difference benween int and NSNumber? Is NSNumber an analog of th object type in C#?
Tell me please in what cases it would be better to use NSInteger type and in what cases NSNumber*?
 

gnasher729

Suspended
Nov 25, 2005
17,980
5,565
What is the difference benween int and NSNumber? Is NSNumber an analog of th object type in C#?
Tell me please in what cases it would be better to use NSInteger type and in what cases NSNumber*?

int is a primitive data type.
NSInteger is a typedef for a primitive data type.
NSNumber is an Objective-C class.

Lets say you want to write a function that takes two integer numbers as parameters, calculates their product, and prints the result. Write that function, then write a main function that uses your function to print the product of 12 and 59.

After that, create an NSDictionary that has the strings "width" and "height" as keys with values 2000 and 1500.

When you've done both, answer the question yourself.
 

lee1210

macrumors 68040
Jan 10, 2005
3,182
3
Dallas, TX
I'm not a C# guy, but from what I just read the "value types" (I call them primitives) are all aliased to structs in the System class. Primitives will be autoboxed and unboxed to these structs as context warrants. Java behaves this way, too, having wrappers for primitives to/from which it will autobox. In Objective-C NSNumber wraps just about any primitive (no pointers, I believe), but it's manual unlike the other two languages discussed here. Go through what gnasher729 suggested (maybe do so in C#, too) and see what you get.

-Lee
 

sam256

macrumors newbie
Original poster
Oct 4, 2011
4
0
gnasher729, lee1210, thank you for you responsivness!! you answers have helped me a lot!!
 

Sydde

macrumors 68030
Aug 17, 2009
2,552
7,050
IOKWARDI
I'm not a C# guy, but from what I just read the "value types" (I call them primitives) are all aliased to structs in the System class. Primitives will be autoboxed and unboxed to these structs as context warrants. Java behaves this way, too, having wrappers for primitives to/from which it will autobox. In Objective-C NSNumber wraps just about any primitive (no pointers, I believe), but it's manual unlike the other two languages discussed here. Go through what gnasher729 suggested (maybe do so in C#, too) and see what you get.

-Lee

I think you could convince NSNumber to wrap a pointer if you cast the pointer to a primitive, but the result would be pretty useless for much of anything.
 

subsonix

macrumors 68040
Feb 2, 2008
3,551
79
I think you could convince NSNumber to wrap a pointer if you cast the pointer to a primitive, but the result would be pretty useless for much of anything.

You would still not wrap a pointer, you would store a memory address in a primitive.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.