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

# setXattr(named:to:on:policy:context: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, context: FSContext, replyHandler reply: @escaping @Sendable (FSSetXattrResult?, (any Error)?) -> Void)
```

```
func setXattr(named name: FSFileName, to value: Data?, on item: FSItem, policy: FSVolume.SetXattrPolicy, context: FSContext) async throws -> FSSetXattrResult
```

## 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.

`context`

An object that enables context-aware file system decisions throughout the operation.

`reply`

A block or closure to indicate success or failure. If setting the attribute succeeds, pass an instance of [`FSSetXattrResult`](/documentation/FSKit/FSSetXattrResult) containing the volume’s updated free space, along with a `nil` error. If setting the attribute fails, pass the relevant error as the second parameter; FSKit ignores the [`FSSetXattrResult`](/documentation/FSKit/FSSetXattrResult) instance in this case. For an `async` Swift implementation, there’s no reply handler; simply return the result instance or throw an error.

---

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)