<!--
{
  "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/setConstantValues:type:withRange:",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Metal"
    ],
    "preciseIdentifier" : "c:objc(cs)MTLFunctionConstantValues(im)setConstantValues:type:withRange:"
  },
  "title" : "setConstantValues:type:withRange:"
}
-->

# setConstantValues:type:withRange:

Sets values for a group of function constants within a specific index range.

```
- (void) setConstantValues:(const void *) values type:(MTLDataType) type withRange:(NSRange) range;
```

## Parameters

`values`

A pointer to the constant values.

`type`

The data type of the function constants.

`range`

The range of the function constant indices.

## Discussion

Declare multiple function constants in Metal Shading Language (MSL).

```metal
constant bool a [[ function_constant(0) ]];
constant bool b [[ function_constant(1) ]];
constant bool c [[ function_constant(2) ]];
```

Set their values by assigning an index range of an array.

```objective-c
const bool abc[3] = { true, true, true };
MTLFunctionConstantValues* constantValues = [MTLFunctionConstantValues new];
[constantValues setConstantValues:&abc
                             type:MTLDataTypeBool
                        withRange:NSMakeRange(0, 3)];
```

---

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)