<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.10.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 6.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreMedia",
  "identifier" : "/documentation/CoreMedia/CMMetadataCreateIdentifierForKeyAndKeySpace(allocator:key:keySpace:identifierOut:)",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "Core Media"
    ],
    "preciseIdentifier" : "c:@F@CMMetadataCreateIdentifierForKeyAndKeySpace"
  },
  "title" : "CMMetadataCreateIdentifierForKeyAndKeySpace(allocator:key:keySpace:identifierOut:)"
}
-->

# CMMetadataCreateIdentifierForKeyAndKeySpace(allocator:key:keySpace:identifierOut:)

Creates a URL-like string identifier that represents a key or keyspace tuple.

```
func CMMetadataCreateIdentifierForKeyAndKeySpace(allocator: CFAllocator?, key: CFTypeRef, keySpace: CFString, identifierOut: UnsafeMutablePointer<CFString?>) -> OSStatus
```

## Parameters

`allocator`

The allocator to use for creating the identifier.

`key`

Key data; may be `CFString`, `CFNumber`, or `CFData`.

`keySpace`

Keyspace; must be string of one to four printable ASCII characters.

`identifierOut`

Upon return, a pointer to the created identifier.

## Return Value

If successful, a nonzero result code. See [Metadata Identifier Error Codes](/documentation/CoreMedia/metadata-identifier-errors).

## Discussion

Metadata entities are identified by a key whose interpretation is defined by its keyspace. When writing metadata to a QuickTime Movie, this tuple is part of the track’s format description.

See [Metadata Identifier Keyspaces](/documentation/CoreMedia/metadata-identifier-keyspaces) for the current list of supported keyspaces and the requirements for key values in each keyspace.

As a matter of convenience, known keyspaces allow for a key to be passed in using a variety of `CFType`s. Note that what is returned by [`CMMetadataCreateKeyFromIdentifier(allocator:identifier:keyOut:)`](/documentation/CoreMedia/CMMetadataCreateKeyFromIdentifier(allocator:identifier:keyOut:)) depends upon the keyspace, and may be a different `CFType` than what is passed to this routine (see the discussion below for what `CFType`s are returned for known keyspaces). To get a key represented as `CFData`, call [`CMMetadataCreateKeyFromIdentifierAsCFData(allocator:identifier:keyOut:)`](/documentation/CoreMedia/CMMetadataCreateKeyFromIdentifierAsCFData(allocator:identifier:keyOut:)).

Some keyspaces use `OSType`s (a.k.a. `FourCharCode`s) to define their keys, and as such their keys are four bytes in length. For these keyspaces, a key may be passed as a `CFNumber`, a `CFString`, or a `CFData`. A key passed as a `CFNumber` will have its value retrieved as <doc://com.apple.documentation/documentation/CoreFoundation/CFNumberType/sInt32Type> comprising the four bytes of the key’s numeric value in big-endian byte order. A key passed as a `CFString` must be a valid ASCII string of four characters. A key passed as a `CFData` must be comprised of the four bytes of the key’s numeric value in big-endian byte order.

All other keyspaces allow the key to be passed as a `CFString` or `CFData`. In both cases, the key will be interpreted as an ASCII string for the purposes of identifier encoding.

---

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)