<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.11.0 -",
    "tvOS: -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Metal",
  "identifier" : "/documentation/Metal/MTLLibrary/makeFunction(name:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Metal"
    ],
    "preciseIdentifier" : "c:objc(pl)MTLLibrary(im)newFunctionWithName:"
  },
  "title" : "makeFunction(name:)"
}
-->

# makeFunction(name:)

Creates an instance that represents a shader function in the library.

```
func makeFunction(name functionName: String) -> (any MTLFunction)?
```

## Parameters

`functionName`

The name of the function.

## Return Value

An [`MTLFunction`](/documentation/Metal/MTLFunction), or `nil` if the named function isn’t found in the library.

## Discussion

If you call this method to retrieve a function that doesn’t use function constants, it returns an [`MTLFunction`](/documentation/Metal/MTLFunction) instance that you can use to build a render or compute pipeline.

If you call this method to retrieve a function that uses function constants to specialize its behavior, you can only use the returned instance to query the `functionConstants` property for the list of function constants. You can’t use to create a render or compute pipeline. To get a specialized instance that you can use to create a pipeline instance, call the [`makeFunction(name:constantValues:completionHandler:)`](/documentation/Metal/MTLLibrary/makeFunction(name:constantValues:completionHandler:)) method or [`makeFunction(name:constantValues:)`](/documentation/Metal/MTLLibrary/makeFunction(name:constantValues:)) to generate a specialized function.

## See Also

  [Metal Shading Language Guide](https://developer.apple.com/library/archive/documentation/Metal/Reference/MetalShadingLanguageGuide/Introduction/Introduction.html#//apple_ref/doc/uid/TP40014364)

  [Metal Programming Guide](https://developer.apple.com/library/archive/documentation/Miscellaneous/Conceptual/MetalProgrammingGuide/Introduction/Introduction.html#//apple_ref/doc/uid/TP40014221)



---

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)