<!--
{
  "availability" : [
    "iOS: 14.0.0 -",
    "iPadOS: 14.0.0 -",
    "macCatalyst: 14.0.0 -",
    "macOS: 11.0.0 -",
    "tvOS: 14.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Metal",
  "identifier" : "/documentation/Metal/MTLDynamicLibrary/serialize(to:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Metal"
    ],
    "preciseIdentifier" : "c:objc(pl)MTLDynamicLibrary(im)serializeToURL:error:"
  },
  "title" : "serialize(to:)"
}
-->

# serialize(to:)

Writes the contents of the dynamic library to a file.

```
func serialize(to url: URL) throws
```

## Parameters

`url`

The URL for the destination file.

## Discussion

When the methods succeeds, the file contains a representation of the [`MTLLibrary`](/documentation/Metal/MTLLibrary)
from the [`MTLDynamicLibrary`](/documentation/Metal/MTLDynamicLibrary) that creates it,
as well as the binaries it has for the device your app is running on.

Such files may be combined with offline tools to contain the compiled code for multiple devices.

If this MTLDynamicLibrary was created from a file that contained compiled code for multiple devices, the compiled code for all other devices is not written (since only compiled code for the current device was loaded).

---

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)