<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.10.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AVFAudio",
  "identifier" : "/documentation/AVFAudio/AVAudioFile/init(forWriting:settings:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "AVFAudio"
    ],
    "preciseIdentifier" : "c:objc(cs)AVAudioFile(im)initForWriting:settings:error:"
  },
  "title" : "init(forWriting:settings:)"
}
-->

# init(forWriting:settings:)

Opens a file for writing using the specified settings.

```
init(forWriting fileURL: URL, settings: [String : Any]) throws
```

## Parameters

`fileURL`

The path of the file to create for writing.

`settings`

The format of the file to create.

## Return Value

A new `AVAudioFile` instance for writing.

## Discussion

This method infers the file type to create from the file extension of `fileURL`, and overwrites a file at the specified URL if a file exists.

The file opens for writing using the standard format [`AVAudioCommonFormat.pcmFormatFloat32`](/documentation/AVFAudio/AVAudioCommonFormat/pcmFormatFloat32). For more information about the `settings` parameter, see the [`settings`](/documentation/AVFAudio/AVAudioRecorder/settings) property in the [`AVAudioRecorder`](/documentation/AVFAudio/AVAudioRecorder) class.

## See Also

[`url`](/documentation/AVFAudio/AVAudioFile/url)

The location of the audio file.



---

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)