Change NSNumber value by allocating new NSNumber?

Posted by Peter Hajas on Stack Overflow See other posts from Stack Overflow or by Peter Hajas
Published on 2010-03-23T21:19:13Z Indexed on 2010/03/23 21:23 UTC
Read the original article Hit count: 415

I understand that NSNumber is immutable, but I still have the need to change it in my app. I use it because it's an object, and therefore usable with @property (if I could, I would use float or CGFloat in a heartbeat, but sadly, I can't).

Is there any way to just overwrite the old NSNumber instance? I'm trying this:

NSNumber *zero = [[NSNumber alloc] initWithFloat:0.0];
myNSNumber = zero

but this doesn't change the value. This is a simplified version of my code, as I'm changing the root view controller's parameter (I know, not MVC-friendly). Still, the changing of the value should be the same assignment, right? Should I release myNSNumber first? What should I set the @property at for myNSNumber?

Thanks!

© Stack Overflow or respective owner

Related posts about nsnumber

Related posts about iphone