---
title: "createLink(to:named:in:context:replyHandler:)"
framework: fskit
role: symbol
role_heading: Instance Method
path: "fskit/fsvolume/handler/createlink(to:named:in:context:replyhandler:)"
---

# createLink(to:named:in:context:replyHandler:)

Creates a new hard link.

## Declaration

```swift
func createLink(to item: FSItem, named name: FSFileName, in directory: FSItem, context: FSContext, replyHandler reply: @escaping @Sendable (FSCreateLinkResult?, (any Error)?) -> Void)
```

```swift
func createLink(to item: FSItem, named name: FSFileName, in directory: FSItem, context: FSContext) async throws -> FSCreateLinkResult
```

## Parameters

- `item`: The existing item to which to link.
- `name`: The name for the new link.
- `directory`: The directory in which to create the link.
- `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/FSCreateLinkResult containing the doc://FSKit/documentation/FSKit/FSFileName of the newly-created link, the doc://FSKit/documentation/FSKit/FSItem/Attributes of the linked item, 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/FSCreateLinkResult 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 creating the link fails, complete the request with an error with a domain of NSPOSIXErrorDomain and the following error codes: EEXIST if there’s already an item named name in the directory. EMLINK if creating the link would exceed the maximum number of hard links supported on item. ENOTSUP if the file system doesn’t support creating hard links to the type of file system object that item represents.

## See Also

### Working with links

- [FSCreateLinkResult](fskit/fscreatelinkresult.md)
- [createSymbolicLink(named:in:attributes:linkContents:context:replyHandler:)](fskit/fsvolume/handler/createsymboliclink(named:in:attributes:linkcontents:context:replyhandler:).md)
- [FSCreateSymlinkResult](fskit/fscreatesymlinkresult.md)
- [readSymbolicLink(_:context:replyHandler:)](fskit/fsvolume/handler/readsymboliclink(_:context:replyhandler:).md)
- [FSReadSymlinkResult](fskit/fsreadsymlinkresult.md)
