---
title: "init(forWritingTo:)"
framework: foundation
role: symbol
role_heading: Initializer
path: "foundation/filehandle/init(forwritingto:)"
---

# init(forWritingTo:)

Returns a file handle initialized for writing to the file, device, or named socket at the specified URL.

## Declaration

```swift
convenience init(forWritingTo url: URL) throws
```

## Parameters

- `url`: The URL of the file, device, or named socket to access.

## Return Value

Return Value The initialized file handle object or nil if no file exists at url.

## Discussion

Discussion The file pointer is set to the beginning of the file. The returned object responds only to write(_:). When using this method to create a file handle object, the file handle owns its associated file descriptor and is responsible for closing it.
