<!--
{
  "availability" : [
    "iOS: -",
    "iPadOS: -",
    "macCatalyst: -",
    "macOS: -",
    "tvOS: -",
    "visionOS: -",
    "watchOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreFoundation",
  "identifier" : "/documentation/CoreFoundation/CFNumber",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Core Foundation"
    ],
    "preciseIdentifier" : "c:@T@CFNumberRef"
  },
  "title" : "CFNumber"
}
-->

# CFNumber

```
class CFNumber
```

## 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, <doc://com.apple.documentation/documentation/Foundation/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 `CFNumberRef`, and in a function where you see a `CFNumberRef` parameter, you can pass in an NSNumber instance. This fact also applies to concrete subclasses of NSNumber. See [Toll-Free Bridged Types](https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFDesignConcepts/Articles/tollFreeBridgedTypes.html#//apple_ref/doc/uid/TP40010677) for more information on toll-free bridging.

## Topics

### Creating a Number

[`CFNumberCreate(_:_:_:)`](/documentation/CoreFoundation/CFNumberCreate(_:_:_:))

Creates a CFNumber object using a specified value.

### Getting Information About Numbers

[`CFNumberGetByteSize(_:)`](/documentation/CoreFoundation/CFNumberGetByteSize(_:))

Returns the number of bytes used by a CFNumber object to store its value.

[`CFNumberGetType(_:)`](/documentation/CoreFoundation/CFNumberGetType(_:))

Returns the type used by a CFNumber object to store its value.

[`CFNumberGetValue(_:_:_:)`](/documentation/CoreFoundation/CFNumberGetValue(_:_:_:))

Obtains the value of a CFNumber object cast to a specified type.

[`CFNumberIsFloatType(_:)`](/documentation/CoreFoundation/CFNumberIsFloatType(_:))

Determines whether a CFNumber object contains a value stored as one of the defined floating point types.

### Comparing Numbers

[`CFNumberCompare(_:_:_:)`](/documentation/CoreFoundation/CFNumberCompare(_:_:_:))

Compares two CFNumber objects and returns a comparison result.

### Getting the CFNumber Type ID

[`CFNumberGetTypeID()`](/documentation/CoreFoundation/CFNumberGetTypeID())

Returns the type identifier for the CFNumber opaque type.

### Constants

[`CFNumberType`](/documentation/CoreFoundation/CFNumberType)

Flags used by CFNumber to indicate the data type of a value.

[Predefined Values](/documentation/CoreFoundation/predefined-values)

CFNumber provides some predefined number values.

## See Also

  [Property List Programming Topics for Core Foundation](https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFPropertyLists/CFPropertyLists.html#//apple_ref/doc/uid/10000130i)



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)