Framework
- Core Foundation
Overview
CFNumber encapsulates C scalar (numeric) types. It provides functions for setting and accessing the value as any basic C type. It also provides a compare function to determine the ordering of two CFNumber objects. CFNumber objects are used to wrap numerical values for use in Core Foundation property lists and collections.
CFNumber objects are not intended as a replacement for C scalar values and should not be used in APIs or implementations where scalar values are more appropriate and efficient.
Note
In order to improve performance, some commonly-used numbers (such as 0
and 1
) are uniqued. You should not expect that allocating multiple CFNumber instances will necessarily result in distinct objects.
CFNumber is “toll-free bridged” with its Cocoa Foundation counterpart, NSNumber
. This means that the Core Foundation type is interchangeable in function or method calls with the bridged Foundation object. Therefore, in a method where you see an NSNumber *
parameter, you can pass in a CFNumber
, and in a function where you see a CFNumber
parameter, you can pass in an NSNumber instance. This fact also applies to concrete subclasses of NSNumber. See Toll-Free Bridged Types for more information on toll-free bridging.