---
title: "makeFunction(name:constantValues:completionHandler:)"
framework: metal
role: symbol
role_heading: Instance Method
path: "metal/mtllibrary/makefunction(name:constantvalues:completionhandler:)"
---

# makeFunction(name:constantValues:completionHandler:)

Asynchronously creates a specialized shader function.

## Declaration

```swift
func makeFunction(name: String, constantValues: MTLFunctionConstantValues, completionHandler: @escaping @Sendable ((any MTLFunction)?, (any Error)?) -> Void)
```

```swift
func makeFunction(name: String, constantValues: MTLFunctionConstantValues) async throws -> any MTLFunction
```

## Parameters

- `name`: The name of the specialized function.
- `constantValues`: The set of constant values assigned to the function constants. Compilation fails if you don’t provide valid constant values for all required function constants.
- `completionHandler`: A block of code that Metal calls after it creates the specialized function.

## Discussion

Discussion Function constant values are first looked up by their index, then by their name. Metal ignores any values that don’t correspond to a function constant in the named function without generating errors or warnings.

## See Also

### Creating shader function instances

- [makeFunction(name:)](metal/mtllibrary/makefunction(name:).md)
- [makeFunction(name:constantValues:)](metal/mtllibrary/makefunction(name:constantvalues:).md)
- [makeFunction(descriptor:completionHandler:)](metal/mtllibrary/makefunction(descriptor:completionhandler:).md)
- [makeFunction(descriptor:)](metal/mtllibrary/makefunction(descriptor:).md)
