Can I use an NSDecimalNumber anywhere that an NSNumber is expected?

Posted by Nick Forge on Stack Overflow See other posts from Stack Overflow or by Nick Forge
Published on 2010-03-14T04:06:46Z Indexed on 2010/03/14 4:15 UTC
Read the original article Hit count: 389

NSDecimalNumber is a subclass of NSNumber, and from what I can tell, it implements all of the NSNumber methods as expected for an NSNumber instance.

Given that, is it ok to give NSDecimalNumbers to any code that is expecting an NSNumber?

The only possible issue might be code that checks that an argument is an instance of NSNumber, but since NSNumber is a class-cluster, code like this would have to check that the instance is a subclass of NSNumber, and NSDecimalNumber instances should pass the same tests.

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about cocoa