<!--
{
  "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/MTLLibrary/makeFunction(name:constantValues:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Metal"
    ],
    "preciseIdentifier" : "c:objc(pl)MTLLibrary(im)newFunctionWithName:constantValues:error:"
  },
  "title" : "makeFunction(name:constantValues:)"
}
-->

# makeFunction(name:constantValues:)

Synchronously creates a specialized shader function.

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

## Parameters

`name`

The name of the specialized function.

`constantValues`

The set of constant values for the function constants.
The compiler can’t compile the function if any value is invalid for the function constants it requires.

## Return Value

A new [`MTLFunction`](/documentation/Metal/MTLFunction) instance if the method completes successfully;
otherwise Swift throws an error and Objective-C returns `nil`.

## Discussion

Function constant values are first looked up by their index, then by their name.
The compiler ignores any values that don’t correspond to a function constant in the named function,
and doesn’t generate errors or warnings.

---

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)