withFileHandle(forReadingAndWritingAt:options:execute:)
Opens the file at the given path and provides scoped read-write access to it.
- iOS
- 13.0+
- macOS
- 10.15+
- tvOS
- 13.0+
- watchOS
- 6.0+
func withFileHandle<Result>(forReadingAndWritingAt path: FilePath, options: OpenOptions.Write = .newFile(replaceExisting: false), execute: (_ readWrite: ReadWriteFileHandle) async throws -> Result) async throws -> Result
Parameters
Returns
The result of the execute
closure.
The file remains open during lifetime of the execute
block and will be closed automatically before the function returns. Files may also be opened in read-only or write-only mode by with withFileHandle(forReadingAt:options:execute:)
and withFileHandle(forWritingAt:options:execute:)
.