---
title: "setAttributes(_:on:context:replyHandler:)"
framework: fskit
role: symbol
role_heading: Instance Method
path: "fskit/fsvolume/handler/setattributes(_:on:context:replyhandler:)"
---

# setAttributes(_:on:context:replyHandler:)

Sets the given attributes on an item.

## Declaration

```swift
func setAttributes(_ newAttributes: FSItem.SetAttributesRequest, on item: FSItem, context: FSContext, replyHandler reply: @escaping @Sendable (FSSetAttributesResult?, (any Error)?) -> Void)
```

```swift
func setAttributes(_ newAttributes: FSItem.SetAttributesRequest, on item: FSItem, context: FSContext) async throws -> FSSetAttributesResult
```

## Parameters

- `newAttributes`: A request containing the attributes to set.
- `item`: The item on which to set the attributes.
- `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 attributes succeeds, pass an instance of doc://FSKit/documentation/FSKit/FSSetAttributesResult containing the item’s updated attributes and the volume’s updated free space, along with a nil error. If setting attributes fails, pass the relevant error as the second parameter; FSKit ignores the doc://FSKit/documentation/FSKit/FSSetAttributesResult instance in this case. For an async Swift implementation, there’s no reply handler; simply return the result instance or throw an error.

## Discussion

Discussion Several attributes are considered “read-only”, and an attempt to set these attributes results in an error with the code EINVAL. A request may set size beyond the end of the file. If the underlying file system doesn’t support sparse files, allocate space to fill the new file size. Either fill this space with zeroes, or configure it to read as zeroes. If a request sets the file size below the current end-of-file, truncate the file and return any unused space to the file system as free space. Ignore attempts to set the size of directories or symbolic links; don’t produce an error. If the caller attempts to set an attribute not supported by the on-disk file system format, don’t produce an error. The upper layers of the framework will detect this situation.

## See Also

### Working with attributes

- [getAttributes(_:of:context:replyHandler:)](fskit/fsvolume/handler/getattributes(_:of:context:replyhandler:).md)
- [FSItem.GetAttributesRequest](fskit/fsitem/getattributesrequest.md)
- [FSGetAttributesResult](fskit/fsgetattributesresult.md)
- [FSItem.SetAttributesRequest](fskit/fsitem/setattributesrequest.md)
- [FSSetAttributesResult](fskit/fssetattributesresult.md)
