<!--
{
  "availability" : [
    "iOS: 10.0.0 -",
    "iPadOS: 10.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.12.0 -",
    "tvOS: 10.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Metal",
  "identifier" : "/documentation/Metal/MTLFunctionConstantValues/setConstantValue(_:type:withName:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Metal"
    ],
    "preciseIdentifier" : "c:objc(cs)MTLFunctionConstantValues(im)setConstantValue:type:withName:"
  },
  "title" : "setConstantValue(_:type:withName:)"
}
-->

# setConstantValue(_:type:withName:)

Sets a value for a function constant with a specific name.

```
func setConstantValue(_ value: UnsafeRawPointer, type: MTLDataType, withName name: String)
```

## Parameters

`value`

A pointer to the constant value.

`type`

The data type of the function constant.

`name`

The name of the function constant.

## Discussion

The first example declares a single function constant in a Metal Shading Language file.

```metal
constant bool a [[ function_constant(0) ]];
```

The next example sets that Boolean value by providing its specific name.

```swift
var a = true
let constantValues = MTLFunctionConstantValues()
constantValues.setConstantValue(&a, type: .bool, withName: "a")
```

---

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)