---
title: "setXattr(named:to:on:policy:context:replyHandler:)"
framework: fskit
role: symbol
role_heading: Instance Method
path: "fskit/fsvolume/xattrhandler/setxattr(named:to:on:policy:context:replyhandler:)"
---

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

Sets the specified extended attribute data on the given item.

## Declaration

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

```swift
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 doc://FSKit/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 doc://FSKit/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 doc://FSKit/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 doc://FSKit/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.

## See Also

### Reading and writing

- [getXattr(named:of:context:replyHandler:)](fskit/fsvolume/xattrhandler/getxattr(named:of:context:replyhandler:).md)
- [FSGetXattrResult](fskit/fsgetxattrresult.md)
- [listXattrs(of:context:replyHandler:)](fskit/fsvolume/xattrhandler/listxattrs(of:context:replyhandler:).md)
- [FSListXattrsResult](fskit/fslistxattrsresult.md)
- [FSVolume.SetXattrPolicy](fskit/fsvolume/setxattrpolicy.md)
- [FSSetXattrResult](fskit/fssetxattrresult.md)
- [supportedXattrNames(for:)](fskit/fsvolume/xattrhandler/supportedxattrnames(for:).md)
