<!--
{
  "availability" : [
    "iOS: 11.2.0 -",
    "iPadOS: 11.2.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.13.2 -",
    "tvOS: 11.2.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 4.2.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreML",
  "identifier" : "/documentation/CoreML/MLCustomLayer/setWeightData(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Core ML"
    ],
    "preciseIdentifier" : "c:objc(pl)MLCustomLayer(im)setWeightData:error:"
  },
  "title" : "setWeightData(_:)"
}
-->

# setWeightData(_:)

Assigns the weights for the connections within the layer.

```
func setWeightData(_ weights: [Data]) throws
```

## Parameters

`weights`

The data encoded in the `weights` field of the model specification.

## Discussion

Implement this method to assign the weights for all the connections between nodes in your layer. This method is called once after the initialization call. Your implementation should validate the weights and throw an error if the weights do not have the expected shape or values.

The data encoded in the `weights` field of the `.mlmodel` file is loaded and passed into this method. If there are repeated weights in the `.mlmodel` file, they will be listed explicitly in the `weights` array. The weight values are provided in the order that they were defined during the custom layer conversion process. Keep a reference to the `weights` passed in because copying the `weights` array can significantly increase an app’s memory. Avoid modifying values of the weights.

---

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)