<!--
{
  "availability" : [
    "macOS: 27.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "FSKit",
  "identifier" : "/documentation/FSKit/FSVolume/Handler/setAttributes(_:on:context:replyHandler:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "FSKit"
    ],
    "preciseIdentifier" : "c:objc(pl)FSVolumeHandler(im)setAttributes:onItem:context:replyHandler:"
  },
  "title" : "setAttributes(_:on:context:replyHandler:)"
}
-->

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

Sets the given attributes on an item.

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

```
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 [`FSSetAttributesResult`](/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 [`FSSetAttributesResult`](/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

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`](/documentation/FSKit/FSItem/Attributes/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 requests an attribute your file system can’t store, skip it rather than producing an error, and leave it out of [`consumedAttributes`](/documentation/FSKit/FSItem/SetAttributesRequest/consumedAttributes). The system uses [`consumedAttributes`](/documentation/FSKit/FSItem/SetAttributesRequest/consumedAttributes) to determine what the caller observes, and the effect varies by operation.

---

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)