<!--
{
  "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/MTLDevice/makeLibrary(data:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Metal"
    ],
    "preciseIdentifier" : "c:objc(pl)MTLDevice(im)newLibraryWithData:error:"
  },
  "title" : "makeLibrary(data:)"
}
-->

# makeLibrary(data:)

Creates a Metal library instance from a dispatch-data instance that contains the functions in a precompiled Metal library.

```
func makeLibrary(data: dispatch_data_t) throws -> any MTLLibrary
```

## Parameters

`data`

The data from a precompiled Metal library. For more information, see [Building a shader library by precompiling source files](/documentation/Metal/building-a-shader-library-by-precompiling-source-files).

## Return Value

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

## Discussion

In Swift, you can also use the [`makeLibrary(data:)`](/documentation/Metal/MTLDevice/makeLibrary(data:)-7khmh) default implementation, which has a <doc://com.apple.documentation/documentation/Dispatch/DispatchData> parameter.

Use either method if your application manages its own archiving system for libraries — for example, if your app uses a single file that contains several libraries.

---

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)