Fail to Create CGImageMetadata by key "HDRGainMap:HDRGainMapHeadroom"

I am trying to create an empty metadata, and set the HDRGainMapHeadroom at ***. However the final returned mutableMetadata doesn't contain the HDRGainMap:HDRGainMapVersion or HDRGainMap:HDRGainMapHeadroom. But iio:hasXMP exist.

why? Is that the reason that the namespace HDRGainMap is private?

func createHDRGainMapMetadata(version: Int, headroom: Double) -> CGImageMetadata? {
    // Create a mutable metadata object

    let mutableMetadata = CGImageMetadataCreateMutable()

    // Define the namespace for HDRGainMap
    let namespace = "HDRGainMap"

    let xmpKeyPath = "iio:hasXMP"
    let xmpValue = String(true)

    // Set the HDRGainMapVersion item
    let versionKeyPath = "\(namespace):HDRGainMapVersion"
    let versionValue = String(version)

    // Set the version value
    let xmpSetResult = CGImageMetadataSetValueWithPath(mutableMetadata, nil, xmpKeyPath as CFString, xmpValue as CFString)
    if xmpSetResult == false {
        print("Failed to set xmp")
    }

    // Set the version value
    let versionSetResult = CGImageMetadataSetValueWithPath(mutableMetadata, nil, versionKeyPath as CFString, versionValue as CFString)
    if versionSetResult == false {
        print("Failed to set HDRGainMapVersion")
    }

    // Set the HDRGainMapHeadroom item
    let headroomKeyPath = "\(namespace):HDRGainMapHeadroom"
    let headroomValue = String(headroom)


    // Set the headroom value
    let headroomSetResult = CGImageMetadataSetValueWithPath(mutableMetadata, nil, headroomKeyPath as CFString, headroomValue as CFString)
    if headroomSetResult == false {
        print("Failed to set HDRGainMapHeadroom")
    }

    return mutableMetadata
}
Fail to Create CGImageMetadata by key "HDRGainMap:HDRGainMapHeadroom"
 
 
Q