---
title: "makeLibrary(data:)"
framework: metal
role: symbol
role_heading: Instance Method
path: "metal/mtldevice/makelibrary(data:)"
---

# makeLibrary(data:)

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

## Declaration

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

## Parameters

- `data`: The data from a precompiled Metal library. For more information, see doc://com.apple.metal/documentation/Metal/building-a-shader-library-by-precompiling-source-files.

## Return Value

Return Value A new MTLLibrary instance if the method completes successfully; otherwise Swift throws an error and Objective-C returns nil.

## Discussion

Discussion In Swift, you can also use the makeLibrary(data:) default implementation, which has a 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.

## See Also

### Creating shader libraries

- [makeDefaultLibrary()](metal/mtldevice/makedefaultlibrary().md)
- [makeDefaultLibrary(bundle:)](metal/mtldevice/makedefaultlibrary(bundle:).md)
- [makeLibrary(URL:)](metal/mtldevice/makelibrary(url:).md)
- [makeLibrary(source:options:)](metal/mtldevice/makelibrary(source:options:).md)
- [makeLibrary(source:options:completionHandler:)](metal/mtldevice/makelibrary(source:options:completionhandler:).md)
- [makeLibrary(stitchedDescriptor:)](metal/mtldevice/makelibrary(stitcheddescriptor:).md)
- [makeLibrary(stitchedDescriptor:completionHandler:)](metal/mtldevice/makelibrary(stitcheddescriptor:completionhandler:).md)
- [makeLibrary(data:)](metal/mtldevice/makelibrary(data:)-7khmh.md)
- [MTLNewLibraryCompletionHandler](metal/mtlnewlibrarycompletionhandler.md)
- [makeLibrary(filepath:)](metal/mtldevice/makelibrary(filepath:).md)
