<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.5.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreFoundation",
  "identifier" : "/documentation/CoreFoundation/CFErrorCreate(_:_:_:_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "Core Foundation"
    ],
    "preciseIdentifier" : "c:@F@CFErrorCreate"
  },
  "title" : "CFErrorCreate(_:_:_:_:)"
}
-->

# CFErrorCreate(_:_:_:_:)

Creates a new CFError object.

```
func CFErrorCreate(_ allocator: CFAllocator!, _ domain: CFErrorDomain!, _ code: CFIndex, _ userInfo: CFDictionary!) -> CFError!
```

## Parameters

`allocator`

The allocator to use to allocate memory for the new object. Pass `NULL` or [`kCFAllocatorDefault`](/documentation/CoreFoundation/kCFAllocatorDefault) to use the current default allocator.

`domain`

A CFString that identifies the error domain. If this reference is `NULL` or is otherwise not a valid CFString, the behavior is undefined.

`code`

A CFIndex that identifies the error code. The code is interpreted within the context of the error domain.

`userInfo`

A CFDictionary created with [`kCFCopyStringDictionaryKeyCallBacks`](/documentation/CoreFoundation/kCFCopyStringDictionaryKeyCallBacks) and [`kCFTypeDictionaryValueCallBacks`](/documentation/CoreFoundation/kCFTypeDictionaryValueCallBacks). The dictionary is copied with [`CFDictionaryCreateCopy(_:_:)`](/documentation/CoreFoundation/CFDictionaryCreateCopy(_:_:)). If you do not want the userInfo dictionary, you can pass `NULL`, in which case an empty dictionary will be assigned.

## Return Value

A new CFError object. Ownership follows the [The Create Rule](https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFMemoryMgmt/Concepts/Ownership.html#//apple_ref/doc/uid/20001148-103029).

## Discussion

---

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)