---
title: "createItem(named:type:in:attributes:context:replyHandler:)"
framework: fskit
role: symbol
role_heading: Instance Method
path: "fskit/fsvolume/handler/createitem(named:type:in:attributes:context:replyhandler:)"
---

# createItem(named:type:in:attributes:context:replyHandler:)

Creates a new file or directory item.

## Declaration

```swift
func createItem(named name: FSFileName, type: FSItem.ItemType, in directory: FSItem, attributes newAttributes: FSItem.SetAttributesRequest, context: FSContext, replyHandler reply: @escaping @Sendable (FSCreateItemResult?, (any Error)?) -> Void)
```

```swift
func createItem(named name: FSFileName, type: FSItem.ItemType, in directory: FSItem, attributes newAttributes: FSItem.SetAttributesRequest, context: FSContext) async throws -> FSCreateItemResult
```

## Parameters

- `name`: The new item’s name.
- `type`: The new item’s type. Valid values are doc://FSKit/documentation/FSKit/FSItem/ItemType/file or doc://FSKit/documentation/FSKit/FSItem/ItemType/directory.
- `directory`: The directory in which to create the item.
- `newAttributes`: Attributes to apply to the new item.
- `context`: An object that enables context-aware file system decisions throughout the operation.
- `reply`: A block or closure to indicate success or failure. If creation succeeds, pass an instance of doc://FSKit/documentation/FSKit/FSCreateItemResult containing the newly-created doc://FSKit/documentation/FSKit/FSItem, its doc://FSKit/documentation/FSKit/FSFileName, its doc://FSKit/documentation/FSKit/FSItem/Attributes, the updated doc://FSKit/documentation/FSKit/FSItem/Attributes of the parent directory, and the volume’s updated free space, along with a nil error. If creation fails, pass the relevant error as the second parameter; FSKit ignores the doc://FSKit/documentation/FSKit/FSCreateItemResult 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 If an item named name already exists in the directory indicated by directory, complete the request with an error with a domain of NSPOSIXErrorDomain and a code of EEXIST.

## See Also

### Working with items

- [FSFileName](fskit/fsfilename.md)
- [FSItem.ItemType](fskit/fsitem/itemtype.md)
- [FSItem.SetAttributesRequest](fskit/fsitem/setattributesrequest.md)
- [FSCreateItemResult](fskit/fscreateitemresult.md)
- [lookupItem(named:in:context:replyHandler:)](fskit/fsvolume/handler/lookupitem(named:in:context:replyhandler:).md)
- [FSLookupItemResult](fskit/fslookupitemresult.md)
- [removeItem(_:named:from:context:replyHandler:)](fskit/fsvolume/handler/removeitem(_:named:from:context:replyhandler:).md)
- [FSRemoveItemResult](fskit/fsremoveitemresult.md)
- [renameItem(_:inDirectory:named:to:inDirectory:overItem:context:replyHandler:)](fskit/fsvolume/handler/renameitem(_:indirectory:named:to:indirectory:overitem:context:replyhandler:).md)
- [FSRenameItemResult](fskit/fsrenameitemresult.md)
- [reclaimItem(_:replyHandler:)](fskit/fsvolume/handler/reclaimitem(_:replyhandler:).md)
