<!--
{
  "availability" : [
    "macOS: 15.4.0 - 27.0.0"
  ],
  "documentType" : "symbol",
  "framework" : "FSKit",
  "identifier" : "/documentation/FSKit/FSVolume/XattrOperations/setXattr(named:to:on:policy:replyHandler:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "FSKit"
    ],
    "preciseIdentifier" : "c:objc(pl)FSVolumeXattrOperations(im)setXattrNamed:toData:onItem:policy:replyHandler:"
  },
  "title" : "setXattr(named:to:on:policy:replyHandler:)"
}
-->

# setXattr(named:to:on:policy:replyHandler:)

Sets the specified extended attribute data on the given item.

```
func setXattr(named name: FSFileName, to value: Data?, on item: FSItem, policy: FSVolume.SetXattrPolicy, replyHandler reply: @escaping @Sendable ((any Error)?) -> Void)
```

## Parameters

`name`

The extended attribute name.

`value`

The extended attribute value to set. This can’t be `nil`, unless the policy is [`FSVolume.SetXattrPolicy.delete`](/documentation/FSKit/FSVolume/SetXattrPolicy/delete).

`item`

The item on which to set the extended attribute.

`policy`

The policy to apply when setting the attribute. See [`FSVolume.SetXattrPolicy`](/documentation/FSKit/FSVolume/SetXattrPolicy) for possible values.

`reply`

A block or closure to indicate success or failure. If setting the attribute fails, pass an error as the one parameter to the reply handler. If setting the attribute succeeds, pass `nil`. For an `async` Swift implementation, there’s no reply handler; simply throw an error or return normally.

---

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)