Can someone post a full example usage of NSNumber?

iphone, iphone-sdk-3.0, nsnumber, xcode

Solution

What do you mean by "full example usage"? Can you give a context for the kind of example you're looking for?

What do you mean by using something as a "normal" variable?

You can get an `NSNumber` either by using the `numberWithXXX` functions, which returns an autoreleased object, or by doing the standard `alloc`/`init`:

NSNumber* myAllocedNumber = [[NSNumber alloc] initWithFloat:0.0f];
// ...use it...
[myAllocedNumber release];

NSNumber* myAutoreleasedNumber = [NSNumber numberWithFloat:0.0f];

You can later change where your pointer is pointing to, but you can't change the value:

NSNumber* myAutoreleasedNumber = nil;
myAutoreleasedNumber = [NSNumber numberWithFloat:0.0f];
// ...use it...
myAutoreleasedNumber = [NSNumber numberWithInt:1000];

Problem

I'm not even sure, for example, if I can use it like a normal variable. There doesn't appear to be a mutable version. And does mutable mean it's value can be changed?

Original source